Ist setContentIntent (PendingIntent) in NotificationCompat.Builder erforderlich?
Aufruf:
public static void triggerTestNotification(Context ctx, String tag, int id) {
Notification not = new NotificationCompat.Builder(ctx)
.setContentTitle("Title").setContentText("Text")
.setAutoCancel(true) // cancel on click
.setSmallIcon(R.drawable.ic_launcher).build();
NotificationManager notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(tag, id, not);
}
imonCreate()
meiner Haupttätigkeit erbringt:
11-17 15:58:46.198: E/AndroidRuntime(1507): FATAL EXCEPTION: main
11-17 15:58:46.198: E/AndroidRuntime(1507): java.lang.RuntimeException: Unable to start activity ComponentInfo{gr.uoa.di.monitoring.android/gr.uoa.di.monitoring.android.activities.MainActivity}: java.lang.IllegalArgumentException: contentIntent required: pkg=gr.uoa.di.monitoring.android id=0 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)
//...
11-17 15:58:46.198: E/AndroidRuntime(1507): Caused by: java.lang.IllegalArgumentException: contentIntent required: pkg=gr.uoa.di.monitoring.android id=0 notification=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.os.Parcel.readException(Parcel.java:1326)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.os.Parcel.readException(Parcel.java:1276)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.app.NotificationManager.notify(NotificationManager.java:133)
11-17 15:58:46.198: E/AndroidRuntime(1507): at gr.uoa.di.monitoring.android.C.triggerTestNotification(C.java:200)
11-17 15:58:46.198: E/AndroidRuntime(1507): at gr.uoa.di.monitoring.android.activities.MainActivity.onCreate(MainActivity.java:44)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-17 15:58:46.198: E/AndroidRuntime(1507): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
11-17 15:58:46.198: E/AndroidRuntime(1507): ... 11 more
Beachten Sie diecontentIntent erforderlich.
Jedoch die docskönnte nicht klarer sein :
Erforderliche Benachrichtigungsinhalte
Ein Benachrichtigungsobjekt muss Folgendes enthalten:
Ein kleines Icon, gesetzt von setSmallIcon ()
Ein von setContentTitle () festgelegter Titel
Detailtext, gesetzt von setContentText ()
Optionale Benachrichtigungsinhalte und -einstellungen
Alle anderen Benachrichtigungseinstellungen und Inhalte sind optional. Weitere Informationen finden Sie in der Referenzdokumentation zu NotificationCompat.Builder.
Diese Meinung spiegelt sich inverschiedene SOAntworten und führt zu SOFragen (undEin weiterer ein).
Problemumgehung:
final Intent emptyIntent = new Intent();
PendingIntent pi = PendingIntent.getActivity(ctx, NOT_USED,
emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
//...
.setContentIntent(pi).build;
Aber ist das wirklich nötig? Ist all diese Situation eine andereFehler in Android-Dokumenten ? Ist es API-abhängig?
Hinweis: Mein Ziel-SDK ist 17 und läuft auf einem 2.3.7-Telefon