如何将通知的BODY获取到Webview

问题描述 投票:0回答:1

我有一个Webview,例如:string url =“https://www.google.com”; UrlLoad(URL);在我的应用中显示Google,

好的,如果我收到通知并推送,那么Webview将更改页面。

就像字符串url =通知的正文;

对不起,我的英语不好。

谢谢。

PS。我正在使用Xamarin

这是FCM接收

[服务]

   [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]   
   class Firebasemessaging : FirebaseMessagingService
   {
    public override void OnMessageReceived(RemoteMessage message)
    {
        this.SendNotification(message.GetNotification().Body);
        Notification notifi = new 
    Notification(Resource.Drawable.pika,"Handbim");

    }

    private void SendNotification(string body)
    {
        var intent = new Intent(this, typeof(MainActivity));
        intent.AddFlags(ActivityFlags.ClearTop);
        var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
        var defaultsoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
        var notif = new NotificationCompat.Builder(this)
            .SetContentTitle("handbim")
            .SetContentText(body)
            .SetAutoCancel(true)
            .SetSound(defaultsoundUri)
            .SetContentIntent(pendingIntent);

      var notificationManager = NotificationManager.FromContext(this);
        notificationManager.Notify(0,notif.Build());

    }
}
android xamarin
1个回答
0
投票

请使用OnNewIntent来实现您的目标。

1)在LaunchMode =Android.Content.PM.LaunchMode.SingleTop的属性中添加MainActivity,如下所示:

[Activity(Label = "StartStopService", MainLauncher = true,LaunchMode =Android.Content.PM.LaunchMode.SingleTop)]

2)在你的SendNotification方法中,添加以下行:

 intent.PutExtra("url", body);

所以身体将通过意图传递给你的OnNewIntent方法。

3)在你的OnNewIntent中覆盖MaintActivity方法,如下所示:

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);

    string str = intent.GetStringExtra("url");
    Toast.MakeText(this, str, ToastLength.Short).Show();
    web_view.LoadUrl(str);
}

注意:

web_view是全球变量

© www.soinside.com 2019 - 2024. All rights reserved.