
kukuk
App-Anbieter (kostenlos)
Hallo alle zusammen, ich bin jetzt alle Tutorials durchgegangen und ich bekomme es nicht hin, das auch nur eine Head-UP Notification angezeigt wird. kann mir jemand helfen. Ich verwende folgenden Code:
Mein 2. Versuch sieht so aus: Auch das funktioniert nicht.
Code:
Intent intent = new Intent(MainActivity.this, MainActivity.class);
PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,0);
Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle("Title")
.setContentText("Test")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentIntent(pi)
.setPriority(Notification.PRIORITY_HIGH);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0,builder.build());
Mein 2. Versuch sieht so aus: Auch das funktioniert nicht.
Code:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mNotificationManager = (NotificationManager) getSystemService(MainActivity.this.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, createNotification(
true));
createNotification(true);
}
});
}
private Notification createNotification(boolean makeHeadsUpNotification) {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher_background)
.setPriority(Notification.PRIORITY_DEFAULT)
.setCategory(Notification.CATEGORY_MESSAGE)
.setContentTitle("Sample Notification")
.setContentText("This is a normal notification.");
if (makeHeadsUpNotification) {
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(this, MainActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
push, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder
.setContentText("Heads-Up Notification on Android L or above.")
.setFullScreenIntent(fullScreenPendingIntent, true);
}
return notificationBuilder.build();
}
Zuletzt bearbeitet: