Java 应用程序处于后台时Firebase推送通知活动未打开?

Java 应用程序处于后台时Firebase推送通知活动未打开?,java,android,android-push-notification,Java,Android,Android Push Notification,实际上,我正在实现firebasePushNotification服务,该服务工作时没有任何问题。现在,当我接收到push_通知并且我的应用程序通过单击处于前台时,通知意图将被传递到所需的活动,不会出现任何错误。但当应用程序处于后台或未打开时,单击通知不会将意图发送到所需的活动,甚至不会显示任何错误。我试图引用中的一些问题,以便在manifest.xml中添加exported=true选项,但它无法解决我的问题 通知管理器类代码: public void displayNotification(

实际上,我正在实现
firebasePushNotification
服务,该服务工作时没有任何问题。现在,当我接收到
push_通知
并且我的应用程序通过单击处于前台时,通知意图将被传递到所需的活动,不会出现任何错误。但当应用程序处于后台或未打开时,单击通知不会将意图发送到所需的活动,甚至不会显示任何错误。我试图引用中的一些问题,以便在
manifest.xml中添加exported=true选项,但它无法解决我的问题

通知管理器类代码:

public void displayNotification(String title, String body,String post_owner_username,String post_owner_time,
                                String notif_commenter_username,String notif_comment_time,String follower_username,String type) {

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(ctx, Constants.CHANNEL_ID)
                    .setSmallIcon(R.drawable.new_icon)
                    .setContentTitle(title)
                    .setContentText(body);

    Intent i = new Intent(ctx, ProfileHolder.class);
    if (type.equals("likes")) {
        Bundle b = new Bundle();
        b.putString("post_owner_username", post_owner_username);
        b.putString("post_owner_time", post_owner_time);
        b.putString("what", "show_notification_post");
        i.putExtras(b);
        i.putExtra("Open", "starred");
    }
    else if (type.equals("comments")) {
        Bundle b = new Bundle();
        b.putString("post_owner_username",post_owner_username);
        b.putString("post_owner_time", post_owner_time);
        b.putString("notif_commenter_username", notif_commenter_username);
        b.putString("notif_comment_time",notif_comment_time);
        b.putString("what", "show_notification_post");
        i.putExtras(b);
        i.putExtra("Open", "starred");
    }
    else if (type.equals("comment_likes")) {
        Bundle b = new Bundle();
        b.putString("post_owner_username", post_owner_username);
        b.putString("post_owner_time", post_owner_time);
        b.putString("notif_commenter_username", notif_commenter_username);
        b.putString("notif_comment_time", notif_comment_time);
        b.putString("what", "show_notification_post");
        i.putExtras(b);
        i.putExtra("Open", "starred");
    }
    else if (type.equals("follow")||type.equals("follow_request")) {
        Bundle b = new Bundle();
        b.putString("searchUsername", follower_username);
        i.putExtras(b);
        i.putExtra("Open", "search_profile");
    }
   // i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, i, PendingIntent.FLAG_ONE_SHOT);

    /*
    *  Setting the pending intent to notification builder
    * */

    mBuilder.setContentIntent(pendingIntent);

    NotificationManager mNotifyMgr =
            (NotificationManager) ctx.getSystemService(NOTIFICATION_SERVICE);


    if (mNotifyMgr != null) {
        mBuilder.setAutoCancel(true);
        mNotifyMgr.notify(1, mBuilder.build());
    }
}

下面是我如何在应用程序处于后台/关闭状态时通过通知打开特定活动,并通过
Intent
传递数据的过程

应用程序

public class AppConfig extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
    }
}
清单

<service android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

<service android:name=".MyFirebaseInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>

<!-- Don't forget to set exported attribute to true -->
<activity android:name=".MainActivity" android:exported="true"/>

}

如果您使用的是
firebase推送通知

您需要发送一个
单击\u action
属性…以在应用程序处于后台时打开所需的活动

所以试试看

 Intent i = new Intent(click_action);
click\u action
是映射到所需活动的
intent筛选器点击操作是强制性的


而不是显式意图调用-在上述情况下,显式意图调用仅在应用程序位于前台时有效。

非常感谢您的精彩回答,先生。虽然意图传递问题现已解决,但活动未收到捆绑包,如何解决该问题
 Intent i = new Intent(click_action);