2017-10-26 2 views
2

Wie Android-Benachrichtigung an der Spitze? setPriority(Notification.PRIORITY_MAX)Android Notification.PRIORITY_MAX ist veraltet, was ist die Alternative, um Benachrichtigungen oben anzuzeigen?

als Notification.PRIORITY_MAX ist veraltet, was ist die Alternative?

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
       .setContentIntent(pendingIntent) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle("Notification Title") 
       .setContentText("Notification Text") 
       .setPriority(Notification.PRIORITY_MAX) 
       .setAutoCancel(true); 
+0

Beachten Sie, dass Sie nicht mehr die vollständige Kontrolle haben, um "android notification on top" anzuzeigen. – CommonsWare

+0

@CommonsWare müssen Sie 'IMPORTANCE_MAX' im Benachrichtigungskanal selbst einstellen. überprüfe meine Antwort. – Aks4125

Antwort

2

In Android O gab es Einführung von Notification channels. Insbesondere definieren Sie Channel mit constructor. In der Dokumentation kann man den Begriff der Wichtigkeit sehen und das ersetzt die Priorität.

0

PRIORITY_MAX Diese Konstante wurde in API-Ebene 26 nicht mehr verwendet. Verwenden Sie stattdessen IMPORTANCE_HIGH.

PRIORITY_MAX

int PRIORITY_MAX

Diese Konstante in API-Ebene statt 26 Verwendung IMPORTANCE_HIGH aufgegeben.

Höchste Priorität für die wichtigsten Elemente Ihrer Anwendung, die die sofortige Aufmerksamkeit oder Eingabe des Benutzers erfordern.

Konstante Wert: 2 (0x00000002)

// create ios channel 
     NotificationChannel iosChannel = new NotificationChannel(IOS_CHANNEL_ID, 
       IOS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); 
     iosChannel.enableLights(true); 
     iosChannel.enableVibration(true); 
     iosChannel.setLightColor(Color.GRAY); 
     iosChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); 
     getManager().createNotificationChannel(iosChannel); 

https://developer.android.com/reference/android/app/Notification.html#PRIORITY_MIN

+0

Bitte konzentrieren Sie sich auf die Frage (PRIORITY_MAX). Danke für das Erklären * was * zu tun ist, aber auch sagen * wie * es zu tun (wie man mit Wichtigkeit arbeitet). –

-1

nur drei Schritt für Android O-Benachrichtigung für alle Android-Version

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "CHANNEL_ID") 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
       CharSequence name = "Hello";// The user-visible name of the channel. 
       int importance = NotificationManager.IMPORTANCE_HIGH; 
       NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); 
       mNotificationManager.createNotificationChannel(mChannel); 
      } 




mNotificationManager.notify(notificationId, notificationBuilder.build()); 
+0

Bringen Sie sich bei, wie Sie Code in Antwort formatieren. Google es. –

0

Arbeitscode folgen Maximum einstellen Priorität.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
    NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_MAX); 

    // Configure the notification channel. 
    notificationChannel.setDescription("Channel description"); 
    notificationChannel.enableLights(true); 
    notificationChannel.setLightColor(Color.RED); 
    notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000}); 
    notificationChannel.enableVibration(true); 
    notificationManager.createNotificationChannel(notificationChannel); 
} 


NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); 

notificationBuilder.setAutoCancel(true) 
     .setDefaults(Notification.DEFAULT_ALL) 
     .setWhen(System.currentTimeMillis()) 
     .setSmallIcon(R.drawable.ic_launcher) 
     .setTicker("Hearty365") 
     .setPriority(Notification.PRIORITY_MAX) 
     .setContentTitle("Default notification") 
     .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.") 
     .setContentInfo("Info"); 

notificationManager.notify(/*notification id*/1, notificationBuilder.build()); 
Verwandte Themen