1

Ich habe Benachrichtigung mit einer Aktionsschaltfläche in meiner Anwendung erstellt, die in Geräten unter 6.0 aber über 6.0 funktioniert, die Aktion Schaltfläche nicht angeklickt wird, stattdessen die gesamte Benachrichtigung geklickt wird und die Inhaltsabsicht stattdessen ausgelöst wird von Aktionsknöpfen ausstehende Absicht, weiß jemand, wie man in Marschamallow und darüber eine Aktionstaste verwendet.Android-Benachrichtigungsproblem in Marshmallow

Unten ist mein Code: -

Intent downloadCancel = new Intent(); 
    downloadCancel.setAction("CANCEL"); 
    PendingIntent cancelPI = PendingIntent.getBroadcast(this,1,downloadCancel, 0); 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) 
    { 
     Notification.Action actionButton = new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,"Cancel",cancelPI).build(); 
     notification = new Notification.Builder(this) 
       .setContentTitle(title) 
       .setContentText(text) 
       .setSmallIcon(R.drawable.ic_file_download_white_24dp) 
       .setContentIntent(pendingIntent) 
       .setTicker(text) 
       .setWhen(0) 
       .setPriority(Notification.PRIORITY_MAX) 
       .addAction(actionButton).getNotification(); 
    } 
    else 
    { 
     notification = new Notification.Builder(this) 
       .setContentTitle(title) 
       .setContentText(text) 
       .setSmallIcon(R.drawable.ic_file_download_white_24dp) 
       .setContentIntent(pendingIntent) 
       .setTicker(text) 
       .setWhen(0) 
       .setPriority(Notification.PRIORITY_MAX) 
       .addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel", cancelPI).getNotification(); 
    } 

Antwort

0

Ich hatte remoteViews für dieses Problem keine anderen Optionen gab es

0

Verwenden

NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_menu_close_clear_cancel, "Cancel", cancelPI).build(); 

statt

Notification.Action actionButton = new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,"Cancel",cancelPI).build(); 
+0

zu verwenden Ich habe es versucht, aber es zeigt Fehlermeldung, dass NotificationCompat.Action anstelle von Notification.Action on line addAction() verwendet werden kann – Akki

Verwandte Themen