0
A
回答
0
是的。可以做到這一點。退房參考Firebase Notification Github Repo
推送通知將基於兩點
- 發送到特定設備(基於FCM令牌)
- 發送到設備的組被觸發(基於訂閱的話題)
onMessageReceived(RemoteMessage remoteMessage)
將被稱爲如果設備接收到的消息
能訪問REM OTE消息,並以此爲基礎進行的需要和要求
動作我儘量保持簡單的初步發展
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Do nothing if message is null
if (remoteMessage == null) return;
// Data exists
if (remoteMessage.getData().size() > 0) {
// To show the notification pass the entire remote message as string
sendNotification(remoteMessage.getData().toString());
// if you've JSON string then decode and handle accordingly
// Sample
/**
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
sendNotification(JSONObject json); // Need to add method to the class to handle this
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
*/
}
/**
* Create and show a simple notification containing the received FCM message.
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
相關問題
- 1. 發送通知的背景火力地堡的Android
- 2. 火力地堡數據庫通知
- 3. 春季背景/火與遺忘處理
- 4. 如何處理背景以及前景的Firebase通知?
- 5. 背景通知
- 6. 背景處理!
- 7. 火力地堡背景和非活動的通知不顯示的iOS
- 8. 處理電影背景變化
- 9. 背景PHP函數處理
- 10. 從背景通知
- 11. iPhone背景通知
- 12. 火力地堡通知不會從火力地堡控制檯
- 13. 數據從火力
- 14. 郵差 - 火力地堡通知IOS
- 15. 火力地堡推送通知SWIFT 3
- 16. 保存火力地堡通知
- 17. 註冊,火力通知應用啓動
- 18. 火力地堡通知未在後臺
- 19. 火力地堡通知從Android設備
- 20. 火力地堡推送通知僅
- 21. iOS本地通知背景
- 22. 背景通知+ Windows 8
- 23. 火力地堡保存數據時,應用程序是在背景
- 24. 火力地堡推送通知 - 如何出現在通知
- 25. 機器人 - 火力地堡通知推送通知不工作
- 26. 火力地堡通知:狀態欄通知被點擊
- 27. Android處理程序背景
- 28. Clojure中的背景處理
- 29. 通知點擊處理推送通知有效載荷數據
- 30. 通過聚合火力/火力點查詢元素將數據推送到Firebase