当应用程序在后台运行时(未终止(,我需要使用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"
}
我已经测试过它并且工作得很好!
仅当应用在后台运行时