繁体   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