我已經使用了下面的代碼來製作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現在發出錯誤,所以我刪除了敬酒的代碼。 –