2

私は通知を扱っています。

コードは API 15 のエミュレータで完全に動作しています。しかし、API 10 のエミュレータで強制的に閉じることができます。

例外が発生していますjava.lang.IllegalArgumentException: contentIntent required:

マニフェストに次のように書きました

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>

コードは次のとおりです。

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);
}

強制終了のログは

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)

何が問題ですか。

4

1 に答える 1

3

インテントを通知に渡す必要があります。また、いくつかの廃止されたメソッド、つまり setLatestEventInfo を使用していることにも注意してください前進する問題が少なくなります。

于 2012-11-08T07:11:23.200 に答える