[英]How to open any Activity using notification when app is not running in Background?
[英]How to open a specific activity when the app is running in background?
當應用程序使用Firebase
通知系統在后台運行(未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
托盤時,我會收到notificaiton
。 它總是打開默認的意圖活動。 我在這里打開TeamActivity_
做錯了什么(使用android注釋)
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"
}
我已經對其進行了測試,並且工作正常!
僅在應用程序在后台運行時
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.