【发布时间】:2018-11-16 10:51:36
【问题描述】:
我有这个问题:
使用 action_click 通过 PHP 面板发送推送。 Activity 会打开,但上面是白屏。
我如何在那里传输数据:标题、消息、图像(如果有,则默认情况下)
如果您能给我一个如何实现它的工作版本,请提前非常感谢。
对不起,我的英语很糟糕,我是俄罗斯人。
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgingService";
private static final String TITLE = "title";
private static final String EMPTY = "";
private static final String MESSAGE = "message";
private static final String IMAGE = "image";
private static final String ACTION = "action";
private static final String DATA = "data";
private static final String ACTION_DESTINATION = "action_destination";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
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());
Map<String, String> data = remoteMessage.getData();
handleData(data);
} else if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
handleNotification(remoteMessage.getNotification());
}// Check if message contains a notification payload.
}
private void handleNotification(RemoteMessage.Notification RemoteMsgNotification) {
String message = RemoteMsgNotification.getBody();
String title = RemoteMsgNotification.getTitle();
NotificationVO notificationVO = new NotificationVO();
notificationVO.setTitle(title);
notificationVO.setMessage(message);
Intent resultIntent = new Intent(getApplicationContext(), PushTest.class);
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.displayNotification(notificationVO, resultIntent);
notificationUtils.playNotificationSound();
}
private void handleData(Map<String, String> data) {
String title = data.get(TITLE);
String message = data.get(MESSAGE);
String iconUrl = data.get(IMAGE);
String action = data.get(ACTION);
String actionDestination = data.get(ACTION_DESTINATION);
NotificationVO notificationVO = new NotificationVO();
notificationVO.setTitle(title);
notificationVO.setMessage(message);
notificationVO.setIconUrl(iconUrl);
notificationVO.setAction(action);
notificationVO.setActionDestination(actionDestination);
Intent resultIntent = new Intent(getApplicationContext(), PushTest.class);
NotificationUtils notificationUtils = new NotificationUtils(getApplicationContext());
notificationUtils.displayNotification(notificationVO, resultIntent);
notificationUtils.playNotificationSound();
}
}
如何在我的活动中显示数据? Activity 像 PushTest 一样通过 action_click 打开,看到只有一个白屏
【问题讨论】:
标签: android firebase android-intent push-notification firebase-cloud-messaging