[英]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. 我使用以下代码在通知状态上显示一个图标,它在Android 4.2.2中运行良好。
but it crack in Android 2.3.3, why? 但它在Android 2.3.3中破解了,为什么? 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.
我有两部2.2手机LG和HTC。 LG works well but HTC throws IllegalArgumentException exception.
LG运行良好,但HTC抛出IllegalArgumentException异常。 Just add contentIntent to your notification.
只需将contentIntent添加到您的通知中即可。 Some device have issue with parcelling notification and won't show it without contentIntent set.
某些设备存在parcelling通知问题,如果没有contentIntent设置则不会显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.