我需要在应用程序使用Firebase
通知系统在后台运行(未终止)时打开特定活动。根据文档,通知托盘将打开默认活动并将意图发送给它。
要打开特定活动,我添加了<Intent>
到Manifest
文件:
<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_
(使用android注释)
public class MessagingService extends FirebaseMessagingService {
public String TAG = "Data";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
System.out.println("data");
}
}
我的token
有效,因为我可以看到通知托盘。
答案 0 :(得分:0)
让我举个简单的例子。
在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"
}
我已经测试过并且工作得很好!
仅当应用在后台运行
时