如何在Android 10中从通知开始活动?

如何在Android 10中从通知开始活动?,android,push-notification,Android,Push Notification,我实现了Firebase推送通知,但在通知中,我想打开一个特定的活动,它在android 10下运行良好,在android 10中,通知打开应用程序,而不是期望的活动 我在NotiAction中的代码是,但在Android 10或更高版本中不起作用: Intent intent; intent = new Intent(this, MainActivity.class); intent.putExtra("Key", true)

我实现了Firebase推送通知,但在通知中,我想打开一个特定的活动,它在android 10下运行良好,在android 10中,通知打开应用程序,而不是期望的活动

我在NotiAction中的代码是,但在Android 10或更高版本中不起作用:

        Intent intent;
        intent = new Intent(this, MainActivity.class);
        intent.putExtra("Key", true);
        intent.putExtra("Msg", message);
        // Assign channel ID
        String channel_id = "notification_channel";
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);        // Create a Builder object using NotificationCompat
        // class. This will allow control over all the flags
        NotificationCompat.Builder builder
                = new NotificationCompat
                .Builder(getApplicationContext(),
                channel_id)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(title)
                .setContentText(message)
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .setVibrate(new long[]{1000, 1000, 1000,
                        1000, 1000})
                .setOnlyAlertOnce(true);

        NotificationManager notificationManager
                = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        // Check if the Android Version is greater than Oreo

        if (Build.VERSION.SDK_INT
                >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel
                    = new NotificationChannel(
                    channel_id, "web_app",
                    NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(
                    notificationChannel);
        }

        notificationManager.notify(0, builder.build());

没有足够的信息给出详细的答案。请提供一些代码。
同时,您可以检查默认方法,该方法在安卓10上的效果非常好:

您应该将channelid设置为builder

if (Build.VERSION.SDK_INT
                >= Build.VERSION_CODES.O) {
            NotificationChannel notificationChannel
                    = new NotificationChannel(
                    channel_id, "web_app",
                    NotificationManager.IMPORTANCE_HIGH);
            notificationManager.createNotificationChannel(
                    notificationChannel);


            //Add this Line
            builder.setChannelId(channel_id);

        }

请在将通知重定向到特定activityCheck更新问题的位置添加您的代码此方法在Android 10或更高版本中不起作用不,它不能解决我的问题,我的代码在Android 8中准确工作,但对于Android 10,它不能打开desire activity,未通过发送打开的启动器活动和数据intent@hus98ain从哪里发送通知web服务器或应用程序本身并发布代码。我使用firebase推送通知(云消息)