重新安装应用程序显示无用的推送GCM

时间:2014-02-10 14:56:20

标签: android nullpointerexception google-cloud-messaging

我在我的应用程序中实现了推送通知(GCM)一切都很好,但是,当我卸载应用程序并再次安装它时,向我显示推送通知,其中没有消息。我不知道为什么每次安装应用程序时都会发出推送通知。

以下是我的GCM代码我的问题是“sendNotification(message,”“,”“);”它显示我的nullpointer异常。

提前谢谢你。

public void onReceive(Context context, Intent intent) {

        GoogleCloudMessaging gcm = GoogleCloudMessaging
                .getInstance(context);
        ctx = context;
        String messageType = gcm.getMessageType(intent);
        PowerManager pm = (PowerManager) ctx
                .getSystemService(Context.POWER_SERVICE);
        @SuppressWarnings("deprecation")
        PowerManager.WakeLock wl = pm.newWakeLock(
                PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
        wl.acquire();
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
                .equals(messageType)) {
            sendNotification(
                    "Send error: " + intent.getExtras().toString(), "", "");
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
                .equals(messageType)) {
            sendNotification("Deleted messages on server: "
                    + intent.getExtras().toString(), "", "");
        } else {
            Bundle extras = intent.getExtras();
            String message = extras.getString("message");
            System.out.println("message " + message);
            Log.i("message", "" + message);
            //Do parsing here:
            sendNotification(message, "", "");
        }
        setResultCode(Activity.RESULT_OK); 
        wl.release();
    }

    // Put the GCM message into a notification and post it.
    private void sendNotification(String msg, String lati, String longi) {
        mNotificationManager = (NotificationManager) ctx
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Intent i = new Intent(ctx, ListViewItems.class);


        PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, i,
                0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                ctx).setSmallIcon(R.drawable.smallscreen_logo)
                .setContentTitle("Promo Fusion")
                // .setStyle(new NotificationCompat.BigTextStyle()
                // .bigText(msg));
                .setContentText(msg);
        mBuilder.setAutoCancel(true);
        mBuilder.setContentIntent(contentIntent);

        // FOR SOUND..
        Uri notification = RingtoneManager
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(ctx, notification);
        r.play();

        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    }
}

logcat的:

        02-10 21:26:54.910: I/System.out(30141): regid
    02-10 21:26:54.918: I/System.out(30141): sender id348234955373
    02-10 21:26:55.363: D/OpenGLRenderer(30141): Flushing caches (mode 0)
    02-10 21:26:56.472: I/System.out(30141): message null
    02-10 21:26:56.472: I/message(30141): null
    02-10 21:26:59.332: D/OpenGLRenderer(30141): Flushing caches (mode 0)
    02-10 21:26:59.718: D/OpenGLRenderer(30141): Flushing caches (mode 1)
    02-10 21:26:59.796: W/IInputConnectionWrapper(30141): showStatusIcon on inactive InputConnection
    02-10 21:27:01.882: D/PullToRefresh(30141): Setting Padding. L: 0, T: 0, R: 0, B: 0
    02-10 21:27:01.882: D/PullToRefresh(30141): First Visible: 0. Visible Count: 0. Total Items:0
    02-10 21:27:01.910: D/AndroidRuntime(30141): Shutting down VM
    02-10 21:27:01.910: W/dalvikvm(30141): threadid=1: thread exiting with uncaught exception (group=0x40a421f8)
    02-10 21:27:02.043: E/AndroidRuntime(30141): FATAL EXCEPTION: main
    02-10 21:27:02.043: E/AndroidRuntime(30141): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.promocloud.promofusion/com.promocloud.promofusion.ListViewItems}: java.lang.NullPointerException: println needs a message
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.os.Handler.dispatchMessage(Handler.java:99)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.os.Looper.loop(Looper.java:137)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread.main(ActivityThread.java:4424)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at java.lang.reflect.Method.invokeNative(Native Method)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at java.lang.reflect.Method.invoke(Method.java:511)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at dalvik.system.NativeStart.main(Native Method)
    02-10 21:27:02.043: E/AndroidRuntime(30141): Caused by: java.lang.NullPointerException: println needs a message
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.util.Log.println_native(Native Method)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.util.Log.d(Log.java:138)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at com.promocloud.promofusion.ListViewItems.onCreate(ListViewItems.java:140)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.Activity.performCreate(Activity.java:4465)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
    02-10 21:27:02.043: E/AndroidRuntime(30141):    ... 11 more

0 个答案:

没有答案