嘿伙计们我正在尝试将GCM应用到我的应用程序中。但是我出于某种原因不断出现这个恼人的错误:
java.lang.IllegalStateException: No receiver allowed to receive com.google.android.c2dm.permission.SEND
这是我的清单文件:
<!-- GCM -->
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.myapp.user.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.user.permission.C2D_MESSAGE" />
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- GCM -->
<application
<activity
android:name=".Home"
android:configChanges="keyboard|orientation|navigation|locale"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<receiver
android:name=".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="com.myapp.user" />
</intent-filter>
</receiver>
<service
android:name=".GCMIntentService"
android:exported="true"/>
</activity>
</application
可能是错误的原因。我必须说我的项目中没有GCMBroadcastReceiver类我需要一个吗?另外,我必须说我的所有类都在项目内的同一个包/文件夹中。
答案 0 :(得分:1)
<receiver>
和<service>
位于<activity>
内,但应位于<application>
内。
像这样:
<application>
<activity
android:name=".Home"
android:configChanges="keyboard|orientation|navigation|locale"
android:label="@string/app_name"
android:screenOrientation="portrait" >
</activity>
<receiver
android:name=".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="com.myapp.user" />
</intent-filter>
</receiver>
<service
android:name=".GCMIntentService"
android:exported="true"/>
</application>