gpt4 book ai didi

android - 在后台或应用程序关闭时未收到 Firebase 通知

转载 作者:行者123 更新时间:2023-11-29 02:41:31 25 4
gpt4 key购买 nike

应用程序在关闭或后台时不会收到通知。下面是处理通知的我的服务类。通知仅在唯一的应用程序运行时有效。

public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "MyFMService";
Random random = new Random();
int NOTIFICATION_ID = random.nextInt(9999 - 1000) + 1000;

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification();


}

private void sendNotification() {
Intent intent = new Intent(this, NotificationDisplay.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_bouddha_icon)
.setContentTitle("Bouddha Meridian School")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

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

notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
}

最佳答案

你有没有下载 google-service.json 并放在 app 文件夹中?遵循此示例以供引用:http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

关于android - 在后台或应用程序关闭时未收到 Firebase 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43715621/

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