Reputation: 2398
I am working with Notifications.
The code is perfectly working in Emulator with API 15. But I am getting force Close in emulator with API 10.
I am getting Exception java.lang.IllegalArgumentException: contentIntent required:
I wrote following in the manifest
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
The code follows :
void showNotification(String status) {
NotificationManager notificationManager;
notificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
int icon;
if (status.equalsIgnoreCase("ON")) icon = R.drawable.on;
else icon = R.drawable.off;
String tickerText = "Phone Tracker is " + status;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
String expandedText = "Phone Tracker is " + status;
String expandedTitle = "Phone Tracker is " + status;
// launchIntent = PendingIntent.getActivity(context, notificationRef,
// intentSetRamark, 0);
notification.setLatestEventInfo(getApplicationContext(), expandedTitle,
expandedText, null);
notificationManager.notify(1, notification);
notificationManager.cancel(1);
}
The Logs of Force Close are
11-08 09:06:29.769: E/AndroidRuntime(359): FATAL EXCEPTION: main
11-08 09:06:29.769: E/AndroidRuntime(359): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mlost2000free/com.mlost2000free.LostPhoneSettingsActivity}: java.lang.IllegalArgumentException: contentIntent required: pkg=com.mlost2000freeid=1 notification=Notification(vibrate=null,sound=null,defaults=0x0)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.os.Looper.loop(Looper.java:123)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-08 09:06:29.769: E/AndroidRuntime(359): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 09:06:29.769: E/AndroidRuntime(359): at java.lang.reflect.Method.invoke(Method.java:521)
11-08 09:06:29.769: E/AndroidRuntime(359): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-08 09:06:29.769: E/AndroidRuntime(359): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-08 09:06:29.769: E/AndroidRuntime(359): at dalvik.system.NativeStart.main(Native Method)
11-08 09:06:29.769: E/AndroidRuntime(359): Caused by: java.lang.IllegalArgumentException: contentIntent required: pkg=com.mlost2000free id=1 notification=Notification(vibrate=null,sound=null,defaults=0x0)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.os.Parcel.readException(Parcel.java:1251)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.os.Parcel.readException(Parcel.java:1235)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.NotificationManager.notify(NotificationManager.java:110)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.NotificationManager.notify(NotificationManager.java:90)
11-08 09:06:29.769: E/AndroidRuntime(359): at com.mlost2000free.LostPhoneSettingsActivity.showNotification(LostPhoneSettingsActivity.java:429)
11-08 09:06:29.769: E/AndroidRuntime(359): at com.mlost2000free.LostPhoneSettingsActivity.setStatus(LostPhoneSettingsActivity.java:400)
11-08 09:06:29.769: E/AndroidRuntime(359): at com.mlost2000free.LostPhoneSettingsActivity.onCreate(LostPhoneSettingsActivity.java:76)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-08 09:06:29.769: E/AndroidRuntime(359): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
What is the problem.
Upvotes: 2
Views: 2885
Reputation: 5819
You should pass in the Intent to the notification. Also it is worth noting that you are using some deprecated methods namely setLatestEventInfo it might be worth changing over to http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html as this might give you less problems moving forward.
Upvotes: 3