[英]How to open any Activity using notification when app is not running in Background?
This is my Firbase Service code i just want to open an Another Acivity when app is closed or not running in background i done Everything but it wont work please help 这是我的Firbase服务代码,我只想在应用关闭或未在后台运行时打开“另一个交流”,我做了所有但没用的工作,请帮助
private void createNotification(String messageBody, String title, RemoteMessage message)
{
Intent intent = new Intent(this,NotificationScreen.class);
intent.putExtra("type",message.getData().get("json"));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultIntent = PendingIntent.getActivity( this ,0,intent,PendingIntent.FLAG_ONE_SHOT);
Uri notificationSoundURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mNotificationBuilder = new NotificationCompat.Builder( this)
.setContentTitle(title)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),R.drawable.icon))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(notificationSoundURI)
.setContentIntent(resultIntent);
mNotificationBuilder.setSmallIcon(getNotificationIcon(mNotificationBuilder));
//Log.i("data",map.values().toString());
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, mNotificationBuilder.build());
}
private int getNotificationIcon(NotificationCompat.Builder notificationBuilder) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int color = 0x008000;
notificationBuilder.setColor(color);
return R.drawable.icon;
}
return R.drawable.icon;
}
Already applied xml code 已经应用的xml代码
<activity android:name=".NotificationScreen"
>
<intent-filter>
<action android:name="NotificationScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Please help unable to understand .. 请帮助无法理解的..
For Android, you could simply set the value of click_action
parameter in your notification
payload equal to the intent filter of the corresponding activity that you want to open. 对于Android,只需在
notification
有效负载click_action
参数的值设置为等于要打开的相应活动的意图过滤器即可。 As mentioned in the docs (emphasis mine): 如文档中所述(重点是我的):
The action associated with a user click on the notification.
与用户关联的操作单击通知。
If specified, an activity with a matching intent filter is launched when a user clicks on the notification .
如果指定,当用户单击通知时,将启动具有匹配意图过滤器的活动 。
So for example you have this payload: 因此,例如,您具有以下负载:
{
"to": <TOKEN>,
"notification": {
...
"click_action" : "OPEN_ME"
...
}
}
Then you have an Activity in your manifest that has the corresponding intent-filter name (similar to your post): 然后,清单中就有一个具有相应意图过滤器名称的“活动”(类似于您的帖子):
<activity android:name=".NotificationScreen">
<intent-filter>
<action android:name="OPEN_ME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
It should open that specific activity. 它应该打开该特定活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.