Android 基于主题发送fcm通知

Android 基于主题发送fcm通知,android,firebase,push-notification,Android,Firebase,Push Notification,当我们基于主题发送FCM通知时,它会在发送通知后到达订阅主题的设备吗 在FCM通知中,我们收到一条关于RemoteMessage的消息。 In FCM Notification we are getting a message on RemoteMessage. if you want to get a body then call remoteMessage.getNotification().getBody(). //This method is only generating push

当我们基于主题发送FCM通知时,它会在发送通知后到达订阅主题的设备吗

在FCM通知中,我们收到一条关于RemoteMessage的消息。
In FCM Notification we are getting a message on RemoteMessage.
if you want to get a body then call remoteMessage.getNotification().getBody(). 

//This method is only generating push notification
    //It is same as we did in earlier posts
    private void sendNotification(RemoteMessage remoteMessage) {
        Intent resultIntent = new Intent(this, MenuBarActivity.class);
        resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        HashMap<String, String> dataMap = new HashMap<String, String>(remoteMessage.getData());
        resultIntent.putExtra(Constant.KEY_MESSAGE_BODY, dataMap);
        resultIntent.putExtra(Constant.KEY_IS_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
                PendingIntent.FLAG_ONE_SHOT);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(getString(R.string.app_name))
                .setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getData().get(Constant.KEY_BODY)))
                .setContentText(remoteMessage.getData().get(Constant.KEY_BODY))
                .setAutoCancel(true)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
                .setSound(defaultSoundUri);

//        if (!BaseActivity.isInForeground()) {
        notificationBuilder.setContentIntent(pendingIntent);
//        }
        // Generate ID
        long time = new Date().getTime();
        String tmpStr = String.valueOf(time);
        String last4Str = tmpStr.substring(tmpStr.length() - 5);
        int notificationId = Integer.valueOf(last4Str);

        // Sets an ID for the notification
//            int notificationId = Constant.NOTIFICATION_ID;

        // Gets an instance of the NotificationManager service
        NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // Builds the notification and issues it.
        mNotifyMgr.notify(notificationId, notificationBuilder.build());
    }
如果要获取正文,请调用remoteMessage.getNotification().getBody()。 //此方法仅生成推送通知 //这和我们在以前的帖子中做的一样 私有无效发送通知(RemoteMessage RemoteMessage){ Intent resultIntent=新的Intent(这是menubActivity.class); 结果.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); HashMap dataMap=新的HashMap(remoteMessage.getData()); resultIntent.putExtra(Constant.KEY\u MESSAGE\u BODY,dataMap); resultIntent.putExtra(Constant.KEY_是_通知,true); PendingEvent PendingEvent=PendingEvent.getActivity(this,0,resultIntent, 悬挂式帐篷(一杆旗帜); Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知); NotificationCompat.Builder notificationBuilder=新建NotificationCompat.Builder(此) .setSmallIcon(R.mipmap.ic_启动器) .setContentTitle(getString(R.string.app_name)) .setStyle(新的NotificationCompat.BigTextStyle().bigText(remoteMessage.getData().get(Constant.KEY_BODY))) .setContentText(remoteMessage.getData().get(常量.KEY_BODY)) .setAutoCancel(真) .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_启动器)) .setSound(defaultSoundUri); //如果(!BaseActivity.IsInfo重新研磨()){ notificationBuilder.setContentIntent(待定内容); // } //生成ID 长时间=新日期().getTime(); 字符串tmpStr=String.valueOf(时间); 字符串last4Str=tmpStr.substring(tmpStr.length()-5); int notificationId=Integer.valueOf(last4Str); //设置通知的ID //int notificationId=Constant.NOTIFICATION\u ID; //获取NotificationManager服务的实例 NotificationManager mNotifyMgr=(NotificationManager)getSystemService(通知服务); //生成通知并发出通知。 mNotifyMgr.notify(notificationId,notificationBuilder.build()); }