gpt4 book ai didi

android - Firebase 通知在后台不工作

转载 作者:太空狗 更新时间:2023-10-29 14:43:08 29 4
gpt4 key购买 nike

我需要帮助。 Firebase 通知在后台不工作。这是我的代码:

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

Log.d(TAG, "FROM:" + remoteMessage.getFrom());
sharedPreference = getSharedPreferences(Global.SECURETRADE, 0);
UID = sharedPreference.getString(Global.ID, "");


Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)`enter code here`;

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

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

notificationBuilder.setSmallIcon(R.mipmap.small_secure_trade_app_icon);

} else {

notificationBuilder.setSmallIcon(R.drawable.small_secure_trade_app_icon);
}

notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.securetrade_icon));
notificationBuilder.setContentTitle(remoteMessage.getData().get("title"));
notificationBuilder.setContentText(remoteMessage.getData().get("body"));
notificationBuilder.setAutoCancel(true);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setContentIntent(pendingIntent);

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

notificationManager.notify(0, notificationBuilder.build());

}




}

最佳答案

只需从您通过推送通知发送的 json 中删除“通知”部分。只需发送“数据”部分,onMessageReceived 将正常工作

关于android - Firebase 通知在后台不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44643866/

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