Android: java.lang.IllegalStateException: 不允许接收者接收 com.google.android.c2dm.permission.SEND
Android: java.lang.IllegalStateException: No receiver allowed to receive com.google.android.c2dm.permission.SEND
大家好,我正在尝试在我的应用程序中实施 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 class,我需要一个吗?另外我必须说,我所有的 classes 都在项目中的同一个 package/folder 中。
<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>
大家好,我正在尝试在我的应用程序中实施 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 class,我需要一个吗?另外我必须说,我所有的 classes 都在项目中的同一个 package/folder 中。
<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>