我已经开始研究GCM通知了 经过大量的goggling我检查了代码,通过它我可以从GCM Server获得注册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>
请建议我在哪里出错我的帮助会很棒 在此先感谢:)
答案 0 :(得分:0)
尝试复制并粘贴此
<?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>
或 我得到了这个问题的答案。只需删除“gen”文件夹即可。它自动构建。申请工作正常。