Google C2D_MESSAGE权限错误

时间:2013-03-25 01:36:26

标签: android permissions android-manifest android-c2dm

我处于向应用程序添加Google C2D功能的初期阶段。我仔细阅读了文档,但仍然遇到IllegalStateException。首先是我尝试运行我的应用程序时的堆栈:

03-24 21:29:36.425: E/AndroidRuntime(3380): FATAL EXCEPTION: main
03-24 21:29:36.425: E/AndroidRuntime(3380): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maxap.lj3/com.maxap.lj3.MainActivity}:   java.lang.IllegalStateException: Application does not define permission com.maxap.lj3.permission.C2D_MESSAGE
03-24 21:29:36.425: E/AndroidRuntime(3380):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) .......

我在清单中定义了该权限。这是我的清单的副本:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />
   <uses-permission  android:name="android.permissions.INTERNET" />

 <uses-permission android:name="com.maxap.lj3.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
        <uses-permission android:name="com.maxap.lj3.gcm.permission.C2D_MESSAGE" /> 
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

我感谢任何帮助。谢谢。

2 个答案:

答案 0 :(得分:3)

尝试更改:

<uses-permission android:name="com.maxap.lj3.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature"/>

<permission android:name="com.maxap.lj3.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature"/>

您尝试使用com.maxap.lj3.gcm.permission.C2D_MESSAGE权限,但在您的清单中,您没有正确声明它。您需要使用<permission>而不是<uses-permission>来声明它们。

答案 1 :(得分:2)

尝试将您的清单稍微更改为以下内容:

<!-- Settings for GCM -->
<permission
    android:name="com.maxap.lj3.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.maxap.lj3.permission.C2D_MESSAGE" />

<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- 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" />