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

查看:185
本文介绍了Android:java.lang.IllegalStateException:没有收件人允许接收com.google.android.c2dm.permission.SEND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿家伙我试图实施GCM到我的应用程序。然而,由于某种原因,我一直在收到这个令人讨厌的错误:

  java.lang.IllegalStateException:没有收件人允许接收com.google。 android.c2dm.permission.SEND 

这是我的清单文件:

 <! -  GCM  - > 

<! - GCM需要Android SDK版本2.2(API级别8)或更高版本。 - >
< uses-sdk
android:minSdkVersion =8
android:targetSdkVersion =21/>

<使用权限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/>
<! - 允许振动 - >
< 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>

<! - - 接收实际的信息。 - >
<! - 接收注册ID。 - >

< category android:name =com.myapp.user/>
< / intent-filter>
< / receiver>

< service
android:name =。GCMIntentService
android:exported =true/>

< / activity>

错误原因可能是什么。我必须说我的项目中没有GCMBroadcastReceiver类,我需要吗?另外我必须说,我所有的类都在项目中的同一个包/文件夹中。

解决方案 < receiver> < service> 位于您的< activity> 但它应该在< application> 中。



像这样:

 < application> 


$ android $ name
$ android
android:configChanges =keyboard | orientation | navigation | locale
android:label =@字符串/ app_name
android:screenOrientation =portrait>
< / activity>

< receiver
android:name =。GCMBroadcastReceiver
android:permission =com.google.android.c2dm.permission.SEND>
< intent-filter>

<! - - 接收实际的信息。 - >
<! - 接收注册ID。 - >

< category android:name =com.myapp.user/>
< / intent-filter>
< / receiver>

< service
android:name =。GCMIntentService
android:exported =true/>

< / application>


Hey guys I am trying to implement GCM to my app. However I keep getting this annoying error for some reason:

java.lang.IllegalStateException: No receiver allowed to receive com.google.android.c2dm.permission.SEND

Here is my manifest file:

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

What could be the cause of the error. I must say that I don't have a GCMBroadcastReceiver class in my project do I need one? Also I must say that all of my classes are in the same package/folder inside the project.

解决方案

The <receiver> and <service> are inside your <activity> but it should be inside <application>.

Like this:

<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆