2013-04-04 13 views
19

私のAndroidアプリがクラッシュすると、これはlogcatである: -onHandleIntent()でIntentがnullになることはありますか?

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.onStartCopmmandSTART_STICKY を返すと見ることができる知っているが、START_STICKYIntentService.onStartCommand使用しません。)

+0

どのようにインテントがnullであると言うことができますか? onHandleIntent()内の194行目にフォーカスすると、nullが返ってきている可能性があります。 –

+0

ありがとうございます。 私はandroid sdkのjarとソースを持っています。行194は です "String action = intent.getAction();" – NoraBora

+0

一部のシステムでは、インテントはnullであり、渡されるmsg.objがnullの場合は完全に正常です。そこにはヌルチェックはありません。 – Edison

答えて

0

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

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

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); 
} 
+0

私のGCMBroadcastReceiverは何らかのヌルインテントが時々あるので、入力されたインテントがnullであるかどうかを確認する必要があります。私は何が起こるかはわかりませんが、インストール中にnullの意図があります。 – Lev

+0

この問題の解決方法は? –

0

一度私に間違ったURIを渡していました。渡したいと思っていることについての文書を参照してください。

Intent Documentation here.

関連する問題