点击通知后如何导航到活动?

时间:2019-02-28 13:14:55

标签: android firebase push-notification


我有一个活动,可以说SplashActivity。我在清单中声明了此活动,如下所示

<activity
            android:name=".SplashScreen"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />          
            </intent-filter>
        </activity>



在以下条件下可以正常工作
应用程序在后台运行且通知中有效负载中没有 click_action 且用户点击通知,用户导航到SplashActivity



在以下情况下无法正常运行
:应用在后台运行,并且通知中包含一些有效载荷和用户 click_action 点击通知后,用户仍停留在同一屏幕上,通知消失。



在这两种情况下如何打开SplashActivity

请帮助,
预先感谢

1 个答案:

答案 0 :(得分:1)

为此,您必须指定使用PendingIntent对象定义的内容意图,并将其传递给setContentIntent()。

以下代码片段显示了如何在用户点击通知时创建打开活动的基本意图:

upstream node_server {
  server localhost:3000;
}

server {
    listen 80;

     root /home/ec2-user/Elaisian/dist/;
     include /etc/nginx/default.d/*.conf;

    if ($http_x_forwarded_proto = 'http'){
       return 301 https://$host$request_uri;
    }

location /api/ {
   proxy_pass http://node_server/api/;
   proxy_http_version 1.1;
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
 }

 location / {
   try_files $uri $uri/ /index.html;
 }

有关更多信息,请参阅此官方文档 https://developer.android.com/training/notify-user/build-notification.html#java