20

私のAndroidアプリがクラッシュし、これがlogcatです:-

java.lang.NullPointerException
    at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:194)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.os.HandlerThread.run(HandlerThread.java:60)

Android gcm r3 ソースを調べたところ、onHandleIntent() で引数の意図が null であることがわかりました。

これは可能ですか?修正方法は?

Service.onStartCopmmand(null インテントはreturnで見られる可能性があることは知っていますSTART_STICKYIntentService.onStartCommand、使用しませんSTART_STICKY。)

4

2 に答える 2

1

インストール時に一部のデバイスでのみアプリケーションがクラッシュすると思います。これは、インストール中に GCM サービスIntentが他の Google ソースからも一部を受信し、ブロードキャスト レシーバーがこのタイプの を処理する準備ができていないためですIntent

プッシュ通知を介してサーバーからプルする GCM インテントを受信したいだけの場合は、これをハンドル インテント コールで使用します。

protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
        //String msg = intent.getStringExtra("message");
        String from=extras.getString("from");
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {

            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
                sendErrorNotification("Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
                sendErrorNotification("Deleted messages on server: " + extras.toString());
                // If it's a regular GCM message, do some work.
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                // This loop represents the service doing some work.
                for (int i = 0; i < 5; i++) {
                    Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                    }
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                // sendNotification("Received: " + extras.toString());
                /*********ERROR IN SOME DEVICES*****************/

                 if(from.equals("google.com/iid"))
                 {
                     //related to google ... DO NOT PERFORM ANY ACTION
                 }
                 else { 
                   //HANDLE THE RECEIVED NOTIFICATION
                     String msg = intent.getStringExtra("message");
                     sendNotification(msg);
                    Log.i(TAG, "Received: " + extras.toString());
                     }
                 /**************************/
            }
        }
        GcmBroadcastReceiver.completeWakefulIntent(intent);
}
于 2015-06-15T06:06:15.243 に答える