简体   繁体   中英

Firebase MessagingService When app not in debug Mode

Firebase Notifications are not receiving when app is not in debug mode. But In the firebase console it's showing as completed.

Below one is my code

 @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());
    }

How to resolve it? Thanks in advance

I had same issue and you can fix this simply by overriding onCreate and put waitForDebugger method like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM