当应用程序在后台运行时,如何打开特定活动?



当应用程序在后台运行时(未终止(,我需要使用Firebase通知系统打开特定活动。根据文档,通知托盘将打开默认活动并向其发送意图。

为了打开特定活动,我在Manifest文件中添加了一条<Intent>

<intent-filter>
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

通过Postman发送数据作为Post请求:

{ 
"notification" : {
"OPEN_ACTIVITY_1":".activity.TemActivity_",
"body" : "update !"
}, 
"data": {
"type":0,
"question":"open the activity"
},
"to": "dDmXZa9k6-o:APA91bEx91oyYnOyzK3kX839EqbvA2CgY74s-
fLUs8MCYZzVmnp-RpgyI3zicEFVS37K7A4kPpbbqYU9hMBEbs-
PrBXlSTYTOBVd7O3CNvl1vaTEbGIHjLLRTWvEK2VRCvJkhQTXWtr3"
}

但是,当我单击notificaiton托盘时,我收到了通知。它始终打开默认的意向活动。我在这里做错了什么来打开TeamActivity_(使用安卓注释(

编辑-1

public class MessagingService extends FirebaseMessagingService {
public String TAG = "Data";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
System.out.println("data");
}
}

我的token有效,因为我可以看到通知托盘。

我举一个简单的例子。

AndroidManifest中(假设您要打开SampleActivity_(

<activity android:name=".activity.SampleActivity_"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="OPEN_ACTIVITY_1"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

现在提出Post请求

{ 
"notification" : {
"click_action":"OPEN_ACTIVITY_1",
"body" : "new Symulti update !"
}, 
"data": {
"type":0,
"question":"what are you doing?"
},
"to": "cfXBKN_vhFw:APA91bH268KeCeFLlp0OHH-
UNPgR_njeNmJET0PvrcrHe6VLN-
w6UQCCO_LbN0TeNhpjqDDStNnt4t0FGQ6S5puz49QSdsK1BKb8R7Q1uYNpP_
UqsRIETuOh1TRst
JAsfJS7VI7Atpfx"
}

我已经测试过它并且工作得很好!

仅当应用在后台运行时

相关内容

  • 没有找到相关文章