Android 2.3上的推送通知崩溃了.

Android 2.3上的推送通知崩溃了.,第1张

概述我试图用GCM向手机发送推送通知,它在 Android 4的设备上工作正常,但当我尝试在Android 2.3上发送通知应用程序崩溃,我收到此错误 03-13 11:44:25.994: E/AndroidRuntime(3579): FATAL EXCEPTION: IntentService[GCMIntentService-1074787013996-1]03-13 11:44:25.99 我试图用GCM向手机发送推送通知,它在 Android 4的设备上工作正常,但当我尝试在AndroID 2.3上发送通知应用程序崩溃,我收到此错误
03-13 11:44:25.994: E/AndroIDRuntime(3579): FATAL EXCEPTION: IntentService[GCMIntentService-1074787013996-1]03-13 11:44:25.994: E/AndroIDRuntime(3579): java.lang.IllegalArgumentException: contentIntent required: pkg=com.itom.vreauRCA ID=0 notification=Notification(vibrate=default,sound=default,defaults=0xffffffff)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.os.Parcel.readException(Parcel.java:1251)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.os.Parcel.readException(Parcel.java:1235)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.app.Inotificationmanager$Stub$Proxy.enqueueNotificationWithTag(Inotificationmanager.java:274)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.app.notificationmanager.notify(notificationmanager.java:110)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.app.notificationmanager.notify(notificationmanager.java:90)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at com.itom.vreauRCA.GCMIntentService.generateNotification(GCMIntentService.java:71)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at com.itom.vreauRCA.GCMIntentService.onMessage(GCMIntentService.java:36)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at com.Google.androID.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.os.Handler.dispatchMessage(Handler.java:99)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.os.Looper.loop(Looper.java:123)03-13 11:44:25.994: E/AndroIDRuntime(3579):     at androID.os.HandlerThread.run(HandlerThread.java:60)03-13 11:44:26.374: V/GCMbroadcastReceiver(3579): onReceive: com.Google.androID.c2dm.intent.RECEIVE03-13 11:44:26.374: V/GCMbroadcastReceiver(3579): GCM IntentService class: com.itom.vreauRCA.GCMIntentService03-13 11:44:26.374: V/GCMBaseIntentService(3579): Acquiring wakelock03-13 11:44:26.414: V/GCMbroadcastReceiver(3579): onReceive: com.Google.androID.c2dm.intent.RECEIVE03-13 11:44:26.414: V/GCMbroadcastReceiver(3579): GCM IntentService class: com.itom.vreauRCA.GCMIntentService03-13 11:44:26.414: V/GCMBaseIntentService(3579): Acquiring wakelock

这是我的GCMBaseIntentService类

import androID.app.Notification;import androID.app.notificationmanager;import androID.app.PendingIntent;import androID.content.Context;import androID.content.Intent;import androID.util.Log;import com.Google.androID.gcm.GCMBaseIntentService;public class GCMIntentService extends GCMBaseIntentService {    private static final String TAG = "GCMIntentService";    PendingIntent contentIntent;    public GCMIntentService() {        super(GetobIEcte.SENDER_ID);    }    @OverrIDe    protected voID onRegistered(Context context,String registrationID) {        Log.i(TAG,"Device registered: regID = " + registrationID);        Log.d("GCMIntentService","in GCMIntentService");    }    @OverrIDe    protected voID onUnregistered(Context context,"Device unregistered");    }    @OverrIDe    protected voID onMessage(Context context,Intent intent) {        Log.i(TAG,"Received message");        String a = intent.getStringExtra("data");        String b = intent.getStringExtra("data2");        generateNotification(context,a,b);    }    @OverrIDe    protected voID onDeletedMessages(Context context,int total) {        Log.i(TAG,"Received deleted messages notification");    }    @OverrIDe    public voID onError(Context context,String errorID) {        Log.i(TAG,"Received error: " + errorID);    }    @OverrIDe    protected boolean onRecoverableError(Context context,"Received recoverable error: " + errorID);        return super.onRecoverableError(context,errorID);    }    private voID generateNotification(Context context,String message,String Title) {        notificationmanager notificationmanager = (notificationmanager) context                .getSystemService(NOTIFICATION_SERVICE);        Notification notification = new Notification();        notification.icon = R.drawable.ic_launcher;        notification.tickerText = "i-Asigutare";        notification.defaults = Notification.DEFAulT_ALL;        notification.setLatestEventInfo(context,Title,message,null);        notificationmanager.notify(0,notification);    }}
解决方法 问题是关于notification.setLatestEventInfo方法.

该方法在API级别11中为deprecated,鼓励使用Notification.Builder.您还可以查看NotificationCompat.Builder以了解支持库的用法.

如果你仍然想按照自己的方式行事,你应该看看这个问题的接受答案:
Android – notification manager,having a notification without an intent

这清楚地表明使用这样的

notification.setLatestEventInfo(context,contentTitle,contentText,PendingIntent.getActivity(getApplicationContext(),new Intent(),0));
总结

以上是内存溢出为你收集整理的Android 2.3上的推送通知崩溃了.全部内容,希望文章能够帮你解决Android 2.3上的推送通知崩溃了.所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1140786.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存