这似乎是一个相当普遍的问题,没有一个好的答案。我刚刚关注了GC导入消息的谷歌指南,我收到了这个错误:
E/AndroidRuntime(21779): java.lang.RuntimeException: Unable to start activity ComponentInfo{eric.bander.app/eric.bander.app.MenuScreen}: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
E/AndroidRuntime(21779): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
E/AndroidRuntime(21779): at android.app.ActivityThread.access$600(ActivityThread.java:127)
E/AndroidRuntime(21779): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
E/AndroidRuntime(21779): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21779): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21779): at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
E/AndroidRuntime(21779): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21779): Caused by: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at com.google.android.gcm.GCMRegistrar.checkManifest(GCMRegistrar.java:137)
E/AndroidRuntime(21779): at eric.bander.app.MenuScreen.onCreate(MenuScreen.java:43)
E/AndroidRuntime(21779): at android.app.Activity.performCreate(Activity.java:4469)
E/AndroidRuntime(21779): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
这是我的清单文件:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="eric.bander.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="eric.bander.app.permission.C2D_MESSAGE" />
<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="eric.bander.app" />
</intent-filter>
</receiver>
这是MainMenu中的一段代码:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "808426403545");
} else {
Toast.makeText(this, GCMRegistrar.getRegistrationId(this), Toast.LENGTH_LONG).show();
}
我不知道它的相关性,但我的应用程序结构与另一个包中的GCM意图服务是否相同:
eric.bander
-MainMenu.class
eric.bander.misc
-GCMIntentService.class
我希望有人可以帮助解决这个问题,当您关注教程时总会感到沮丧。
TIA
答案 0 :(得分:5)
我的错误是将GCMIntentService放在与注册GCM的类不同的包中。