我想在显示给用户 之前检查通知数据JSON对象是否可能?如果有可能如何做到这一点 感谢您的帮助如何在android显示之前从android中获取数据
0
A
回答
0
在fcm
服务onMessageReceived
其传递到通知
1
首先分析和解析在FCM服务类获得JSON前检查JSON,然后显示通知按要求。
1
如果您使用FCM,则可以使用此服务。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
// [END_EXCLUDE]
// TODO(developer): Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
sendNotification("String From Data Payload");
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
remoteMessage
包含由服务接收的消息。收到消息后,您可以使用remoteData.getData()
来处理您的data
有效载荷,该地址存储为地图。您可以使用remote.getData().get("json_key")
来获得data
有效载荷内发送的json_key
的特定值。
获取数据,你可以使用的方法sendNotification
,具体如下:
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);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.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. 如何从PHP中获取数据并在android listview中显示在FRAGMENT中?
- 2. 如何在android中从json中获取数据并在RecyclerView中显示?
- 3. android从活动中获取数据并在html中显示
- 4. 如何从android中获取Json数据?
- 5. 如何从php中获取JSON数据并在android中显示到textview中?
- 6. 如何从sqlite表中获取数据并将其显示在android的textview中?
- 7. 如何从数据库中获取值并在android应用程序中显示
- 8. 如何在BarChart中显示数据Android
- 9. 如何在Android中从webservice获取图像数据显示图库?
- 10. 如何在显示元素之前从.load()获取新高度
- 11. 如何在android中获取JSON数据
- 12. 如何在Android中获取帧数据
- 13. 在android中显示数据
- 14. 如何从Android服务获取数据?
- 15. 如何获取数据从MySQL到Android
- 16. 如何从iframe获取数据到android?
- 17. 如何从asp.net获取数据到android?
- 18. 如何从Android手机获取数据?
- 19. Android从数据库中获取数据
- 20. 在加载数据之前显示加载到Android的webview
- 21. 在android中从xml获取数据
- 22. 在Android中从Firebase获取数据
- 23. 在Android进程之间获取数据
- 24. 如何在android中的onPause()之前显示Toast消息?
- 25. 如何从wunderground API获取数据并将其显示在Android屏幕上?
- 26. Android - 从数组中获取最新值并在TextView中显示
- 27. 如何获取数字线textView可以在Android中显示
- 28. 如何从ANDROID中的sqlite数据库中获取数据?
- 29. 屏幕闪烁开始在获取数据之前的Android
- 30. 在显示之前获取_detailItem和更改标签数据
谢谢@Anjali –