2017-08-02 42 views
0

我按照this教程,以實現我的目標用戶(即 - Send push notifications所有用戶(設備)和圖像和文字)在前景無論應用程序或背景Android的通知發送給所有使用消息API(ARC)

我的教訓,如果我們使用信息API發送(ARC - 高級REST客戶端)然後用戶會得到通知與圖像和文本兩者都被應用在foreground or background

但我不知道如何將通知發送給所有設備/用戶使用Messaging API (ARC)

我用下面腳本發送通知到單用戶只:

https://fcm.googleapis.com/fcm/send 
Content-Type:application/json 
Authorization:key=AIza************adrTY 

{ "data": { 
    "image": "https://ibin.co/2t1lLdpfS06F.png", 
    "message": "Firebase Push Message Using API" 
    "AnotherActivity": "True" 
    }, 
    "to" : "f25gYF3***********************HLI" 
} 

如果,我將無法使用Messaging API (ARC)然後它會發送通知向所有用戶對我來說好浪費時間。

回答

1

單向訂閱所有用戶到一個主題併發送到主題。

像這樣:

FirebaseMessaging.getInstance().subscribeToTopic("all"); 

,並通知這樣的:

https://fcm.googleapis.com/fcm/send 
Content-Type:application/json 
Authorization:key=AIza************adrTY 

{ "data": { 
    "image": "https://ibin.co/2t1lLdpfS06F.png", 
    "message": "Firebase Push Message Using API" 
    "AnotherActivity": "True" 
    }, 
    "to" : "/topics/all" 
} 
+0

我已經TRID與 「要」: 「/主題/新聞」,但我沒有得到通知,如你可以看到我正在使用這一行:FirebaseMessaging.getInstance()。subscribeToTopic(「news」);在我的代碼MainActivity ... – Sophie

+0

對不起,我沒有注意到,由於互聯網網絡速度慢,我沒有收到通知那個時候,我只是再次發送,發現我越來越......無論如何感謝迅速答覆和幫助。 ..在接下來的2分鐘我會接受你的回答... – Sophie

+0

沒問題:)任何問題只要問@Sophie –

相關問題