简体   繁体   English

当应用未在后台运行时,如何使用通知打开任何活动?

[英]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.

相关问题 当应用程序在后台运行时,如何打开特定活动? - How to open a specific activity when the app is running in background? 收到 firebase 通知时,即使应用程序处于后台,如何打开 Activity - How to Open Activity even when app is in background when receive firebase notification 当应用程序处于后台/未运行时,不打开通知点击的特定活动 - Not opening specific activity on notification click when the app is in background/not running 当应用程序在后台/未运行时,通知单击无法打开特定活动 - Notification click not opening specific activity when the app is in background/not running 从通知“应用程序正在后台运行”打开应用程序 - Open app from notification “App is running in the background” 在后台单击通知时打开特定活动 - Open specific activity when notification clicked in background 当应用程序处于后台时如何在单击通知时打开目标活动 - how opening the targeted activity on click of notification when app is in background 如何在收到通知且应用程序处于后台时调用 android 中的另一个活动 - How to call another activity in android when notification received and app is in background 当应用程序在后台时,如何使用 firebase 通知更改默认启动器活动 - How to change default launcher activity with firebase notification when app in background 从通知进入正在运行的应用程序时,如何完成当前活动 - When entering running app from notification, how to finish current activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM