简体   繁体   English

Android 2.3.3中的NotificationCompat破解,但在Android 4.2.2中运行良好

[英]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.

相关问题 我的应用程序在Android版本2.3.3上运行良好,但在android 4.2.2上无法运行 - My application works fine on Android version 2.3.3 but does not work on android 4.2.2 android padding-在4.2.2中有时会被忽略,在4.0.4中有效 - android padding - sometimes ignored in 4.2.2, works in 4.0.4 Android中的Webview只能在4.2+版本中使用,而不能在2.3.3中使用 - Webview in Android which works in 4.2+ and not in 2.3.3 android app在android 2.3.3中工作正常,但在android 4.1.2中停止 - android app works fine in android 2.3.3 but stops in android 4.1.2 Android NotificationCompat.Builder可以使用三个按钮,但不能使用四个 - Android NotificationCompat.Builder works with three buttons but not four Android NotificationCompat未显示在jar中 - Android NotificationCompat is not showing in jar 在Android 4.0.4中解析json时出现FileNotFoundException,但在Android 2.3.3中有效 - FileNotFoundException while parsing json in android 4.0.4 but works in android 2.3.3 RSA算法适用于Android 4.3,但适用于Android 2.3.3崩溃 - RSA algorithm works for Android 4.3 but crash for Android 2.3.3 我的应用程序在 android 2.3.3 到 android 3.1 上运行,但在 4.0 + 上因错误而停止 - My App works on android 2.3.3 to android 3.1 but stops with error on 4.0 + WebView在4.2.2中不会显示静态HTML,但在2.3.3中可以使用 - WebView won't display static HTML in 4.2.2, but works in 2.3.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM