0

经过大量的观察后,我开始研究 GCM 通知,我检查了代码,通过它我可以从 GCM 服务器获取注册 ID,所以我使用了

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);

final String regId= GCMRegistrar.getRegistrationId(this);

if (regId.equals("")) {
  GCMRegistrar.register(this, "338056690461");
}
else{
  Log.v(TAG, "Already registered");
}

  But When i run My Application i get error on   `CheckMAnifest()`

这意味着我的清单中有错误,但我认为我的清单是正确的,请查看我的异常以及清单

它给出的例外

java.lang.IllegalStateException: Application does not define permission PushNotification.Pop.permission.C2D_MESSAGE

我使用的清单是

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="PushNotification.Pop"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <permission
        android:name="PushNotification.Pop.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="PushNotification.Pop.permission.C2D_MESSAGE" />

    <!-- App receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM connects to Google Services. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <application android:debuggable="true" android:label="@string/app_name" >
        <activity
            android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="PushNotification.Pop" />
            </intent-filter>
        </receiver>

       <service android:name=".GCMIntentService" />
    </application>

</manifest>

请建议我哪里出错了,您的帮助将非常感谢提前:)

4

1 回答 1

0

try to copy and paste this

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="PushNotification.Pop"
      android:versionCode="1"
      android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8" 
              android:targetSdkVersion="17"/>


    <!-- GCM connects to Internet Services. -->
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH" />
    <uses-permission android:name="android.permission.CALL_PHONE"/>  
    <uses-permission android:name="android.permission.VIBRATE" /> 


    <uses-permission android:name="android.permission.WAKE_LOCK" />

   <uses-permission android:name="PushNotification.Pop.permission.C2D_MESSAGE" /> 

     <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 


     <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 


     <permission
        android:name="indieswebs.magento.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />  

    <application android:icon="@drawable/ic_launcher" 
                 android:label="@string/app_name"
                >

        <activity android:name="PushNotification.Pop.MainActivity"
                  android:label="@string/app_name_title"
                  android:clearTaskOnLaunch="true"
                  android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>




    <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="PushNotification.Pop" />
            </intent-filter>
        </receiver>

        <service android:name="PushNotification.Pop.GCMIntentService" />

    </application>
</manifest>

or I got answer for this issue. Just delete "gen"folder . It build automatically. Application will work fine.

于 2013-05-10T07:11:32.523 回答