gpt4 book ai didi

android - 在android后台从firebase发送通知时没有通知声音和振动和灯光

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

我正在从 firebase 向我的 Android 应用程序发送推送通知。但是当我的应用程序处于后台时,不会调用 firebase onMessageReceived 方法,而是 firebase 向系统发送通知以在系统托盘中显示通知。通知出现在系统托盘中,但没有通知声音,即使我在系统设置中允许我的应用程序发出通知声音。这是我的通知代码谢谢

    private void sendNotification(String msg, String title) {
NotificationManager mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class), 0);
Intent i = new Intent(this,MainActivity.class);
i.putExtra("","");

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
//Vibration
mBuilder.setVibrate(new long[] { 200, 400, 600, 800, 1000 });

//LED
mBuilder.setLights(Color.MAGENTA, 1000, 1000);

//Ton
mBuilder.setSound(Uri.parse("android.resource://"
+ getApplicationContext().getPackageName() + "/" + R.raw.circles_notif));
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(0, mBuilder.build());
}

最佳答案

从您的 firebase 控制台转到“通知”>“新消息”>“高级选项”并将通知作为自定义数据发送。使用 'title' 和 'body' 作为 Key 并按照您想要在通知中显示的方式放置它们的值。当您的应用程序处于后台或被终止时,这应该调用 onMessageReceived()。

如果您从自己的服务器发送通知,这里是一个示例 json 部分:

{   
"data": {
"title": "notification_title",
"body": "notification_body"
},
"to" : "jh578_gsh....jhHGFJ76FH"
}

关于android - 在android后台从firebase发送通知时没有通知声音和振动和灯光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39351560/

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