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. 春季背景/火與遺忘處理
- 2. 如何處理背景以及前景的Firebase通知?
- 3. 背景通知
- 4. 背景處理!
- 5. 火力地堡背景和非活動的通知不顯示的iOS
- 6. 處理電影背景變化
- 7. iPhone背景通知
- 8. 從背景通知
- 9. 火力地堡通知不會從火力地堡控制檯
- 10. 數據從火力
- 11. 需要通過火力數據
- 12. 郵差 - 火力地堡通知IOS
- 13. 火力地堡推送通知僅
- 14. 火力地堡通知未在後臺
- 15. 保存火力地堡通知
- 16. 背景通知+ Windows 8
- 17. 火力地堡通知:狀態欄通知被點擊
- 18. 火力地堡推送通知 - 如何出現在通知
- 19. 機器人 - 火力地堡通知推送通知不工作
- 20. Clojure中的背景處理
- 21. Android處理程序背景
- 22. 通過聚合火力/火力點查詢元素將數據推送到Firebase
- 23. 在火力數據庫
- 24. 如何火力數據
- 25. 更新數據火力
- 26. 如何火力數據庫
- 27. 找回火力數據
- 28. 尋找火力地堡通知FirebaseMessaging的UserInfo字段文檔
- 29. 發送火力地堡通知與文件PHP
- 30. Android:傳遞數據的背景中的FCM推送通知