Reputation: 322
I want to create a notification but the application crashed after calling last line.
NotificationCompat.Builder notification =
new NotificationCompat.Builder(this)
.setContentTitle("My notification")
.setContentText("Hello World!");
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notification.build());
In LogCat I found this:
12-15 19:30:27.828: W/dalvikvm(22020): threadid=1: thread exiting with uncaught exception (group=0x40015560)
12-15 19:30:27.838: E/AndroidRuntime(22020): FATAL EXCEPTION: main
12-15 19:30:27.838: E/AndroidRuntime(22020): java.lang.IllegalArgumentException: contentIntent required: pkg=com.example.test id=1 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x0)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Parcel.readException(Parcel.java:1326)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Parcel.readException(Parcel.java:1276)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.NotificationManager.notify(NotificationManager.java:133)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.NotificationManager.notify(NotificationManager.java:104)
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.example.test.MainActivity.onClick(MainActivity.java:55)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.view.View.performClick(View.java:2506)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.view.View$PerformClick.run(View.java:9112)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Handler.handleCallback(Handler.java:587)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Handler.dispatchMessage(Handler.java:92)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.os.Looper.loop(Looper.java:130)
12-15 19:30:27.838: E/AndroidRuntime(22020): at android.app.ActivityThread.main(ActivityThread.java:3835)
12-15 19:30:27.838: E/AndroidRuntime(22020): at java.lang.reflect.Method.invokeNative(Native Method)
12-15 19:30:27.838: E/AndroidRuntime(22020): at java.lang.reflect.Method.invoke(Method.java:507)
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
12-15 19:30:27.838: E/AndroidRuntime(22020): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
12-15 19:30:27.838: E/AndroidRuntime(22020): at dalvik.system.NativeStart.main(Native Method)
12-15 19:35:27.888: I/Process(22020): Sending signal. PID: 22020 SIG: 9
I try it on my mobile phone with Android version 2.3.7. Any help?
Upvotes: 1
Views: 1544
Reputation: 27246
java.lang.IllegalArgumentException: contentIntent required: pkg=com.example.test id=1
You are not giving your notification a contentIntent and since you use the Compat version, you must supply either an Intent (activity to open when the user taps the notification) or if you use RemoteViews, you can use PendingIntents applied to individual views.
Upvotes: 3