Android:java.lang.IllegalStateException:不允许接收者接收 com.google.android.c2dm.permission.SEND

Posted

技术标签:

【中文标题】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 【发布时间】:2015-10-05 13:05:55 【问题描述】:

大家好,我正在尝试在我的应用中实施 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 类,我需要一个吗?另外我必须说我所有的类都在项目内的同一个包/文件夹中。

【问题讨论】:

【参考方案1】:

&lt;receiver&gt;&lt;service&gt; 在您的 &lt;activity&gt; 内,但它应该在 &lt;application&gt; 内。

像这样:

<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>

【讨论】:

以上是关于Android:java.lang.IllegalStateException:不允许接收者接收 com.google.android.c2dm.permission.SEND的主要内容,如果未能解决你的问题,请参考以下文章

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

解决:Retrofit请求返回: Expected a string but was BEGIN_OBJECT at line 1 column 4832 path $

Android逆向系列文章— Android基础逆向

Android 逆向Android 权限 ( Android 逆向中使用的 android.permission 权限 | Android 系统中的 Linux 用户权限 )