簡體   English   中英

Firebase MessagingService 當應用程序未處於調試模式時

[英]Firebase MessagingService When app not in debug Mode

當應用程序未處於調試模式時,不會收到 Firebase 通知。 但在 firebase 控制台中,它顯示為已完成。

下面一個是我的代碼

 @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        context = (EEmployeeApplication) EEmployeeApplication.getContext();
        Log.d("Notification","From: "+remoteMessage.getFrom());
        if (remoteMessage.getData().size() > 0){
            Log.d("FCM","Message data payload: "+remoteMessage.getData());
        }
        if (remoteMessage.getNotification() != null) {
            Log.d("FCM", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }
        if (remoteMessage.getNotification() != null) {
            Log.d("FCM", "Message Notification Body Verse: " + remoteMessage.getData().get("PLAN_ID"));
            String PlanID = remoteMessage.getData().get("PLAN_ID");
            context.eEMPSharedPreference.setNotification(PlanID);
        }
        if (remoteMessage.getNotification() != null) {
            Log.d("FCM", "Message Notification Click action: " + remoteMessage.getNotification().getClickAction());
        }
        String image = remoteMessage.getNotification().getIcon();
        String title = remoteMessage.getNotification().getTitle();
        String text = remoteMessage.getNotification().getBody();
        int id = 0;
        Object obj = remoteMessage.getData().get("id");
        if (obj != null){
            id = Integer.valueOf(obj.toString());
        }
        this.sendNotification(new NotificationData(image,id,title,text));
    }

    private void sendNotification(NotificationData notificationData){
        Intent intent = new Intent(this, Navigationdrawer.class);
        intent.putExtra(NotificationData.TEXT,notificationData.getTextMessage());
        PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notificationBulder = new NotificationCompat.Builder(this);
        notificationBulder.setContentTitle(notificationData.getTitle());
        notificationBulder.setContentText(notificationData.getTextMessage());
        notificationBulder.setAutoCancel(true);
        //notificationBulder.setSmallIcon(R.mipmap.ic_launcher);
        notificationBulder.setContentIntent(pendingIntent);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(notificationData.getId(), notificationBulder.build());
    }

如何解決? 提前致謝

我有同樣的問題,你可以簡單地通過重寫 onCreate 並像這樣放置 waitForDebugger 方法來解決這個問題:

override fun onCreate() {
       Debug.waitForDebugger()
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM