简体   繁体   中英

GCM android Error receiving broadcast Intent { act=DISPLAY.MESSAGE flg=0x10 (has extras)

I have troubles when I start the app and register device in Gcm

Any idea how to fix it?

The rest is working fine, I receive the notification and correctly.

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            Log.v("MESSAGE", intent.getExtras().getString("message") );
            String newMessage = intent.getExtras().getString("message");
            // Waking up mobile if it is sleeping
            aController.acquireWakeLock(getApplicationContext());       
            Toast.makeText(getApplicationContext(), "Got Message: " + newMessage, Toast.LENGTH_LONG).show();
            // Releasing wake lock
            aController.releaseWakeLock();
        }
    };

Error

01-10 20:11:09.945: W/dalvikvm(20161): threadid=1: thread exiting with uncaught exception (group=0x40c5a1f8)
01-10 20:11:09.945: E/AndroidRuntime(20161): FATAL EXCEPTION: main
01-10 20:11:09.945: E/AndroidRuntime(20161): java.lang.RuntimeException: Error receiving broadcast Intent { act=example.gcm.testing.DISPLAY_MESSAGE flg=0x10 (has extras) } in example.gcm.testing.MainActivity$1@41a0a2d8
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:737)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.os.Handler.handleCallback(Handler.java:605)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.os.Looper.loop(Looper.java:137)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.app.ActivityThread.main(ActivityThread.java:4517)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at java.lang.reflect.Method.invokeNative(Native Method)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at java.lang.reflect.Method.invoke(Method.java:511)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at dalvik.system.NativeStart.main(Native Method)
01-10 20:11:09.945: E/AndroidRuntime(20161): Caused by: java.lang.NullPointerException
01-10 20:11:09.945: E/AndroidRuntime(20161):    at example.gcm.testing.MainActivity$1.onReceive(MainActivity.java:146)
01-10 20:11:09.945: E/AndroidRuntime(20161):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)

your code for extra is returning null,

String newMessage = intent.getExtras().getString("message");

use try catch, and make sure you have extra to be received from there!

Try

Log.v("MESSAGE", intent.getExtras().getString("price"));
String newMessage = intent.getExtras().getString("price");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM