通知点击后如何打开片段?火力地堡

时间:2017-10-04 14:21:37

标签: java android firebase android-fragments firebase-cloud-messaging

我创建了一个函数" send_notification"使用firebase函数和node.js,现在最后很难弄清楚如何在我的FirebaseMessagingService类中打开Fragment而不是Activity。

这是我的代码

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);



        String notification_title = remoteMessage.getNotification().getTitle();
        String notification_message = remoteMessage.getNotification().getBody();


        NotificationCompat.Builder mBuilder =
                (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                        .setSmallIcon(R.mipmap.logo_login)
                        .setContentTitle(notification_title)
                        .setContentText(notification_message);




        //i need to open a fragment not Main Activiti
        Intent resultIntent = new Intent(this, MainActivity.class);

        PendingIntent resultPendingIntent =
                PendingIntent.getActivity(
                        this,
                        0,
                        resultIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );

        mBuilder.setContentIntent(resultPendingIntent);

        //----------------------------------------------------










        int mNotificationId = (int) System.currentTimeMillis();
        NotificationManager mNotifyMgr =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mNotifyMgr.notify(mNotificationId, mBuilder.build());



    }


}

0 个答案:

没有答案