简体   繁体   中英

NotificationCompat crack in Android 2.3.3 but works well in Android 4.2.2

I use the following code to show a icon on Notification status, it works well in Android 4.2.2.

but it crack in Android 2.3.3, why? Thanks!

findViewById(R.id.btnLog).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //------------------------------------
                NotificationCompat.Builder mBuilder =
                        new NotificationCompat.Builder(getApplicationContext())
                        .setSmallIcon(R.drawable.smsforward)
                        .setContentTitle("My notification")
                        .setContentText("Hello World!");

                NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);               
                mNotificationManager.notify(12356, mBuilder.build());               

                //------------------------------------

            }
        }); 

here is the stacktrace:

02-24 05:55:22.925: E/AndroidRuntime(543): FATAL EXCEPTION: main
02-24 05:55:22.925: E/AndroidRuntime(543): java.lang.IllegalArgumentException: contentIntent required: pkg=info.dodata.smsforward id=12356                    

                         notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x0)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.os.Parcel.readException(Parcel.java:1326)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.os.Parcel.readException(Parcel.java:1276)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.app.NotificationManager.notify(NotificationManager.java:111)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.app.NotificationManager.notify(NotificationManager.java:91)
02-24 05:55:22.925: E/AndroidRuntime(543):  at ui.SMSMain$5.onClick(SMSMain.java:130)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.view.View.performClick(View.java:2485)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.view.View$PerformClick.run(View.java:9080)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.os.Handler.handleCallback(Handler.java:587)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.os.Handler.dispatchMessage(Handler.java:92)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.os.Looper.loop(Looper.java:123)
02-24 05:55:22.925: E/AndroidRuntime(543):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-24 05:55:22.925: E/AndroidRuntime(543):  at java.lang.reflect.Method.invokeNative(Native Method)
02-24 05:55:22.925: E/AndroidRuntime(543):  at java.lang.reflect.Method.invoke(Method.java:507)
02-24 05:55:22.925: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-24 05:55:22.925: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-24 05:55:22.925: E/AndroidRuntime(543):  at dalvik.system.NativeStart.main(Native Method)

Yeah, I have same thing on some devices. I have two 2.2 phones LG and HTC. LG works well but HTC throws IllegalArgumentException exception. Just add contentIntent to your notification. Some device have issue with parcelling notification and won't show it without contentIntent set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM