java.lang.IllegalStateException:没有用于操作的接收器com.google.android.c2dm.intent.REGISTRATION

时间:2014-09-22 07:37:55

标签: android

我知道这个问题已被提出,但这些答案没有帮助。

我在某些特定设备(如三星标签3)上遇到错误,并且它在三星galaxy s3手机上运行良好。

我想在支持Google Play服务的所有设备上运行我的应用程序。还有其他应用,包括gcm和在三星标签3上运行良好。

我的manifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.gcm.demo.app"
android:versionCode="1"
android:versionName="1.0" >

<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<!--
     The targetSdkVersion is optional, but it's always a good practice
     to target higher versions.
-->
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />

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

<!--
 Creates a custom permission so only this app can receive its messages.

 NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
       where PACKAGE is the application's package name.
-->
<permission
    android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.google.android.gcm.demo.app.permission.C2D_MESSAGE" />

<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<!-- Main activity. -->
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name=".DemoActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <!--
      BroadcastReceiver that will receive intents from GCM
      services and handle them to the custom IntentService.

      The com.google.android.c2dm.permission.SEND permission is necessary
      so only GCM services can send data messages for the app.
    -->
    <receiver
        android:name="com.google.android.gcm.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.google.android.gcm.demo.app" />
        </intent-filter>
    </receiver>

    <service android:name="com.google.android.gcm.demo.app.GCMIntentService" />
</application>

我的错误日志: -

    09-22 13:03:06.625: E/AndroidRuntime(22439): FATAL EXCEPTION: main
09-22 13:03:06.625: E/AndroidRuntime(22439): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gcm.demo.app/com.google.android.gcm.demo.app.DemoActivity}: java.lang.IllegalStateException: No receivers for action com.google.android.c2dm.intent.REGISTRATION
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2129)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2154)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread.access$700(ActivityThread.java:146)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1260)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.os.Looper.loop(Looper.java:137)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread.main(ActivityThread.java:4949)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at java.lang.reflect.Method.invokeNative(Native Method)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at java.lang.reflect.Method.invoke(Method.java:511)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1043)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at dalvik.system.NativeStart.main(Native Method)
09-22 13:03:06.625: E/AndroidRuntime(22439): Caused by: java.lang.IllegalStateException: No receivers for action com.google.android.c2dm.intent.REGISTRATION
09-22 13:03:06.625: E/AndroidRuntime(22439):    at com.google.android.gcm.GCMRegistrar.checkReceiver(GCMRegistrar.java:184)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at com.google.android.gcm.GCMRegistrar.checkManifest(GCMRegistrar.java:169)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at com.google.android.gcm.demo.app.DemoActivity.onCreate(DemoActivity.java:54)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.Activity.performCreate(Activity.java:5185)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
09-22 13:03:06.625: E/AndroidRuntime(22439):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
09-22 13:03:06.625: E/AndroidRuntime(22439):    ... 11 more

1 个答案:

答案 0 :(得分:0)

您尚未实现接收器以接收GCM回调。

 <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="smart.emergencyservice" />
        </intent-filter>
    </receiver>

    <service android:name="smart.emergencyservice.GCMIntentService" />

然后使GCMIntentService扩展GCMBaseIntentService