[英]How can I disable firebase notification on android client app
當用戶通過設置關閉通知時,我想禁用 firebase 通知服務。
我發現了有關此主題的問題:
Android 上的 Firebase - 我想在 Android 客戶端上禁用 Firebase 通知
和
但答案是忽略通知的另一種方式。
有沒有其他方法可以取消注冊 firebase 通知。
謝謝
用這個。
FirebaseMessaging.getInstance().unsubscribeFromTopic("X");
我花了很多時間來了解如何在后台應用程序時禁用顯示推送通知。 當應用程序在前台時一切都清楚,您可以處理應用程序中的所有內容 - 當用戶在應用程序設置中關閉通知時,您只是不顯示通知。 但是當應用程序在后台時,Firebase 會在后台處理所有內容,您不能覆蓋FirebaseMessagingService
方法,因為它們是最終的。 我發現了一些非常骯臟的解決方案,可能有人說這很愚蠢,但我所做的是覆蓋了FirebaseMessagingService
onCreate 並做了下一步:
private void removePush(){
new Handler().postDelayed(() -> {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= 23) {
StatusBarNotification[] notifications = manager.getActiveNotifications();
for (StatusBarNotification n : notifications) {
if (n.getTag().contains("campaign_collapse_key_")) {
Logger.logD(TAG + ": Found firebase push. remove it.");
manager.cancel(n.getTag(), n.getId());
}
}
}
else{
manager.cancelAll();
}
}, 500);
}
如果此解決方案對某人有幫助 - 很好。 如果您找到更好的解決方案,請讓所有人知道;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.