我已经使用了下面的代码来制作Log,Toast并从onMessageReceived发送广播到服务。在onMessageReceived中没有显示ToMessageReceived的FireBase Colud消息服务
我能够在日志中看到使用Firebase控制台发送的数据。但吐司不显示,广播也不发送。
代码如下:
class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Toast.makeText(getApplicationContext(),"From: " + remoteMessage.getFrom(),Toast.LENGTH_SHORT).show();
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());
Toast.makeText(getApplicationContext(),"Toast shown",Toast.LENGTH_LONG).show();
Intent i = new Intent();
i.setAction("firebase.message.combinedthings");
sendBroadcast(i);
}
}
}
感谢您的回答。我解决了问题我现在可以发送广播,而Toast现在发出错误,所以我删除了敬酒的代码。 –