我有一个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());
}
}
请使用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
是全球变量