从 FCM 通知访问、打开或编辑 Web 视图

Acces, open, or edit a webview from FCM notification

我在我的应用程序中实现了 android FCM,我的应用程序只在 WebView 中加载一个网络应用程序。

我想在收到(并单击)FCM 通知后更改 webview 的 url。 我在 "MyFirebaseMessagingService.java" 中管理通知,特别是在 sendNotification 方法中。

private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, Principal.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

/*HERE I WANNA ACCES, CREATE OR EDIT A WEBVIEW*/


    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Formación Alcalá")
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(messageBody))
            .setContentText(messageBody);



    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

我觉得这应该是可以的。拜托,有人可以指导我吗? P.D。抱歉我的英语不好。

检查这个

Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.putExtra("URl", Your URL);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |            Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent =      PendingIntent.getActivity(getApplicationContext(),notificationIndex,notification    Intent,PendingIntent.FLAG_UPDATE_CURRENT);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(getApplicationContext(), notificationTitle,      notificationMessage, pendingNotificationIntent);

并且在您的主要 Activity 中:

Bundle extras = intent.getExtras();
if(extras != null){
    if(extras.containsKey("NotificationMessage"))
    {
        setContentView(R.layout.viewmain);
        // extract the extra-data in the Notification
        String url= extras.getString("URl");
        webview.loadurl(url);
    }
}