gpt4 book ai didi

android - 在我的应用程序中关闭推送通知

转载 作者:行者123 更新时间:2023-11-29 19:41:39 27 4
gpt4 key购买 nike

在我的应用程序中成功实现了 Firebase 以发送关于我的博客的推送通知,但现在我想知道用户如何“关闭”我发送到应用程序的通知,这是我的代码:

package com.lfcchile;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

/**
* Created by Jona on 7/23/16.
*/
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_menu_destacado)
.setContentTitle("LFC Chile")
.setContentText(remoteMessage.getNotification().getBody())
.setTicker("Ticker")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

}

}

有想法吗?提前致谢!!

最佳答案

您可以添加某种共享首选项,并存储从用户那里获得的值。然后在收到通知后先获取值,如果用户的值在这种情况下为真,则跳过通知的创建。

关于android - 在我的应用程序中关闭推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38558114/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com