2017-08-03 62 views
1

我研究和唯一的答案,我能找到要麼說:如何以編程方式備份​​通知欄?

  1. 如何被拉低禁用通知欄。
  2. 如何使用取消通知:

    NotificationManager notificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0);

這兩個都不是我所要求的,因爲通知被取消的很好。我在通知中設置了兩項操作:「解除」和「打開活動」。顧名思義,點擊兩者後,上述代碼將執行並清除通知,但不會導致通知欄恢復。這是必需的,特別是當第二次通知操作導致啓動活動時。

我嘗試了Android棒棒糖和牛軋糖,並且通知欄也沒有恢復。所以如果有人能夠告訴我這是否可能,以及如何。 謝謝。

建設的通知代碼:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this); 

    builder 
      .setSmallIcon(icon).setTicker(message).setWhen(when) 
      .setAutoCancel(true).setContentTitle("Kindly record your Voice") 
      .setColor(Color.RED); 


    notificationIntent = new Intent(this,ReminderReceiver.class); 
    notificationIntent.setAction("Record"); 
    PendingIntent pendIntent1 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.addAction(R.drawable.common_google_signin_btn_icon_dark, "Record", pendIntent1); 


    notificationIntent2 = new Intent(this, ReminderReceiver.class); 
    notificationIntent2.setAction("Dismissed"); 

    PendingIntent pendIntent2 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent2, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.addAction(R.drawable.starticon, "Dismiss", pendIntent2); 

    notificationIntent3 = new Intent(this, CancelReceiver.class); 
    PendingIntent pendIntent3 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent3, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setDeleteIntent(pendIntent3); 

    notification = builder.build(); 


    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(1, notification); 
+0

您是否在通知構建器中嘗試過.setAutoCancel(true)? –

+0

是的,我有。沒有幫助。 – Neurostic

+0

您是否在活動中使用此代碼? NotificationManager notificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); 爲什麼你要爲所有通知設置相同的通知ID,你是否只想要一個通知? –

回答

1

似乎不可思議,但通知欄不上去的時候不存在其他通知。如果您的是唯一的通知,則點擊後該欄會自動向上滑動。

+0

作品!這是酒吧不能恢復的唯一原因。 – Neurostic

相關問題