Android 当点击fcm通知时,不进入特定活动,并输入意图
我正在开发一款带有fcm通知的android应用程序。 我处理通知,并为每种通知类型指定特定的类。 但是当我点击通知时,它会引导我进入主要活动(我不想要它,也不把它放在意图中),我不知道我错过了什么 这是我的代码:Android 当点击fcm通知时,不进入特定活动,并输入意图,android,notifications,Android,Notifications,我正在开发一款带有fcm通知的android应用程序。 我处理通知,并为每种通知类型指定特定的类。 但是当我点击通知时,它会引导我进入主要活动(我不想要它,也不把它放在意图中),我不知道我错过了什么 这是我的代码: 它总是在if(PreferenceManager.getDefaultSharedReferences(this.getBoolean(“isActive”,true))上输入的,这就是为什么,在前后检查put log,这会给你造成问题的原因感谢你的回答,但即使我关闭了它,问题仍然存
它总是在
if(PreferenceManager.getDefaultSharedReferences(this.getBoolean(“isActive”,true))
上输入的,这就是为什么,在前后检查put log,这会给你造成问题的原因感谢你的回答,但即使我关闭了它,问题仍然存在!,我将更新我的代码问题。尽管如此,您仍然有类型
条件,我建议您在这些条件下使用日志,并检查是否达到代码块,然后您将无法执行任何操作,因为您需要有数据通知,它在后台/前台和kill状态下工作非常感谢@RakeshKumar我使用此选项获取值并处理通知操作:它总是在if(PreferenceManager.getDefaultSharedPreferences(this.getBoolean(“isActive”,true))
上输入,这就是为什么,检查前后的put log,这会让你有理由感谢你的answar,但即使我把它删除了,如果关闭了,这个问题仍然存在!,我将更新我的代码问题。尽管如此,您仍然有类型
条件,我建议您在这些条件下使用日志,并检查是否达到代码块,然后您将无法执行任何操作,因为您需要有数据通知,它在后台/前台和杀戮状态下工作非常感谢@RakeshKumar我获得值并使用以下选项处理通知操作:
private void sendNotification(String messageBody, String title) {
Intent intent;
EventObject eventObject = new EventObject(0,"","");
if(type.equals("order_pending") ){
intent = new Intent(this, orderDetailsActivity.class)
.putExtra("orderId", order_id);
eventObject = new EventObject(Integer.parseInt(order_id),"order_pending", messageBody);
}
else if( type.equals("order_declined")) {
intent = new Intent(this, orderDetailsActivity.class)
.putExtra("orderId", order_id);
eventObject = new EventObject(Integer.parseInt(order_id) ,"order_declined", messageBody);
}
else {
intent = new Intent(this, MainActivity.class);
eventObject = new EventObject(1,"Activate Agent",messageBody);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.logo)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int f =0;
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
EventBus.getDefault().post(eventObject);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}