当我在设备上安装应用程序后3到4个小时运行正常,我的项目中已经集成了Fcm通知,此后我无法收到任何通知。我认为它仅在oreo中发生,因为它在我的miui牛轧糖设备中起作用。 -我想在收到消息时进行公开活动。这是我的android代码:
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "Message " + remoteMessage.getNotification());
Log.d(TAG, "Message1 " + remoteMessage.getData());
JSONObject jsonObject = new JSONObject(remoteMessage.getData());
try {
f_Id = jsonObject.getString("fid");
Log.d(TAG, "F_ID" + f_Id);
} catch (JSONException e) {
e.printStackTrace();
}
mContext = getApplicationContext();
util = new Util(mContext);
back_suburllist = new ArrayList<>();
createNotificationChannel();
getApiData();
}
public void getApiData(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Intent openActivity = new Intent(mContext, Activity_Transparant.class);
openActivity.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_NEW_TASK);
openActivity.putExtra("listBundleActivity", bundle);
mContext.startActivity(openActivity);
} else {
Intent intent = new Intent(mContext, BackLoadUrlService.class);
intent.putExtra("listBundleValue", bundle);
mContext.startService(intent);
}
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String CHANNEL_ID = mContext.getString(R.string.default_notification_channel_id);
CharSequence name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}