Android onHandleIntent()中的意图怎么可能为空?

Android onHandleIntent()中的意图怎么可能为空?,android,google-cloud-messaging,Android,Google Cloud Messaging,我的android应用程序崩溃,这是日志:- java.lang.NullPointerException at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:194) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android

我的android应用程序崩溃,这是日志:-

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()中的参数intent为null

这可能吗?如何修复它

(我知道
Service.onstartcommand
returning
START\u STICKY

但是
IntentService.onStartCommand
不使用
START\u STICKY

我认为应用程序只有在安装期间才会在某些设备上崩溃。这是因为在安装过程中,GCM服务还从其他Google源接收到一些
Intent
,而您的广播接收器不准备处理此类
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);
}
protectedvoid onHandleIntent(意图){
Bundle extras=intent.getExtras();
//String msg=intent.getStringExtra(“消息”);
stringfrom=extras.getString(“from”);
GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(this);
字符串messageType=gcm.getMessageType(intent);
如果(!extras.isEmpty()){
if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)){
sendErrorNotification(“发送错误:+extras.toString());
}else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)){
sendErrorNotification(“服务器上的已删除邮件:+extras.toString());
//如果是常规GCM消息,请执行一些操作。
}else if(GoogleCloudMessaging.MESSAGE\u TYPE\u MESSAGE.equals(messageType)){
//此循环表示正在执行某些工作的服务。
对于(int i=0;i<5;i++){
Log.i(标记“Working…”+(i+1)+“/5@”+SystemClock.elapsedRealtime());
试一试{
睡眠(500);
}捕捉(中断异常e){
}
}
Log.i(标记“Completed work@”+SystemClock.elapsedRealtime());
//接收到消息的Post通知。
//sendNotification(“已收到:+extras.toString());
/*********某些设备中存在错误*****************/
if(from.equals(“google.com/iid”))
{
//与谷歌相关…不要执行任何操作
}
否则{
//处理收到的通知
String msg=intent.getStringExtra(“消息”);
发送通知(msg);
Log.i(标记“Received:+extras.toString());
}
/**************************/
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}

有一次,我传递了错误的URI。参考文档了解您想要通过的意图


你怎么能说意图是无效的??请关注onHandleIntent()中的第194行,可能还有其他内容变为空…谢谢您的回复。因为我有来自android sdk的jar和源代码。第194行是“String action=intent.getAction();”在某些系统上,intent为null,如果传递的msg.obj为null,则这是完全正常的。在这里没有空检查。考虑把你的声音添加到这个bug报告中,我同意,我的GCMBLASTCASTER有时会收到一些空的意图,所以我必须检查传入的意图是否为空。我不知道会发生什么,但我在安装过程中得到了一个空的意图。关于这个问题的任何更新如何解决和检查这个问题?