gpt4 book ai didi

安卓火力地堡 : Huawei p8 push Notification is not shown in system when app is in background?

转载 作者:行者123 更新时间:2023-11-29 17:04:23 25 4
gpt4 key购买 nike

根据 Firebase Documentation :

当 App 处于前台时:

onMessageReceived 被调用,我可以显示推送通知并对数据进行任何处理(在这种情况下我没问题)。

当 App 在后台时:

通知系统托盘将显示通知,一旦用户点击通知,启动器 Activity 就会被调用,通知数据将通过 bundle 传递给启动器 Activity 。

我的问题是,当应用程序处于后台时,通知系统不显示通知。

我没有使用 Firebase 控制台,因为我无法将数据 添加到通知负载。所以我使用了 RESTful 客户端 API,但它仍然是同样的问题。

要求:

URL:https://fcm.googleapis.com/fcm/send
Method type: POST
Content-Type: application/json
Authorization : key=AAAAFi0N5KM....
Body:

{
"priority" : "high",
"notification" : {
"body" : "This week’s edition is now available.",
"title" : "NewsMagazine.com",
"icon" : "new",
"click_action": "OPEN_ACTIVITY_1" ,
"sound" : "mySound"

},
"data": {
"title": "title " ,
"body": "any vaslue "
},
"registration_ids": ["fVNdKJsWtNQ:APA91bEJ...."]
}

响应:

{
"multicast_id": 6105324374411246344,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1486655756341577%dc81f05ff9fd7ecd"
}
]
}

此技术在应用程序处于前台时有效,但在后台时不起作用

安卓代码:

public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
sendNotification(remoteMessage.getData().get("title"),remoteMessage.getData().get("body"));
}

private void sendNotification(String messageTitle,String messageBody) {
Intent intent = new Intent(this, SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0 /* request code */, intent,PendingIntent.FLAG_UPDATE_CURRENT);

long[] pattern = {500,500,500,500,500};

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.roshetta_logo_home)
.setContentTitle(messageTitle)
.setContentText(messageBody)
.setAutoCancel(true)
.setVibrate(pattern)
.setLights(Color.BLUE,1,1)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

list

  <service android:name=".Util.PushNotification.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".Util.PushNotification.MyFirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>

最佳答案

每次我们在华为手机上遇到问题,都是因为该应用不是“ protected 应用”。

  1. 转到设置
  2. 向下滚动并点按“高级设置”
  3. 点击电池管理器
  4. 找到 protected 应用并选择它
  5. 找到您的应用,并将其设置为 protected

关于安卓火力地堡 : Huawei p8 push Notification is not shown in system when app is in background?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42141950/

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