PutExtra值未通过使用xamarin表单和android的推送通知传递给mainactivity
我目前的目标是在点击成功接收到的推送通知后,打开应用程序到特定页面。我会在基本工作完成后发送一个id。由于某些原因,在点击通知后,id不会被传递回mainactivity BroadcastReceiver类发送推送通知PutExtra值未通过使用xamarin表单和android的推送通知传递给mainactivity,android,xamarin.forms,android-notifications,main-activity,Android,Xamarin.forms,Android Notifications,Main Activity,我目前的目标是在点击成功接收到的推送通知后,打开应用程序到特定页面。我会在基本工作完成后发送一个id。由于某些原因,在点击通知后,id不会被传递回mainactivity BroadcastReceiver类发送推送通知 var uiIntent = new Intent(this, typeof(MainActivity)); uiIntent.PutExtra("param", "54"); var pendingIntent = PendingIntent.GetActivity(t
var uiIntent = new Intent(this, typeof(MainActivity));
uiIntent.PutExtra("param", "54");
var pendingIntent = PendingIntent.GetActivity(this, 0, uiIntent, 0);
主要活动-onCreate
string parameterValue = this.Intent.GetStringExtra("param");
if (parameterValue != null)
{
LoadApplication(new App(parameterValue));
}
else
{
LoadApplication(new App(null));
}
看起来很简单,但是我的参数值总是空的谢谢
更新
private void CreateNotification(string title, string desc)
{
//Create notification
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
Intent startupIntent = new Intent(this, typeof(MainActivity));
startupIntent.PutExtra("param", "54");
Android.App.TaskStackBuilder stackBuilder = Android.App.TaskStackBuilder.Create(this);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
stackBuilder.AddNextIntent(startupIntent);
const int pendingIntentId = 0;
PendingIntent pendingIntent =
stackBuilder.GetPendingIntent(pendingIntentId, PendingIntentFlags.OneShot);
// var pendingIntent = PendingIntent.GetActivity(this, 0, startupIntent, 0);
////Create an intent to show ui
//var uiIntent = new Intent(this, typeof(MainActivity));
//uiIntent.PutExtra("param", "54");
//var pendingIntent = PendingIntent.GetActivity(this, 0, uiIntent, 0);
//Create the notification using Notification.Builder
//Use Android Compatibility Apis
var notification = new NotificationCompat.Builder(this).SetContentTitle(title)
.SetSmallIcon(Android.Resource.Drawable.SymActionEmail)
//we use the pending intent, passing our ui intent over which will get called
//when the notification is tapped.
.SetContentIntent(pendingIntent)
.SetContentText(desc)
.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
//Auto cancel will remove the notification once the user touches it
.SetAutoCancel(true).
Build();
//Show the notification
if (notificationManager != null)
{
notificationManager.Notify(1, notification);
}
}
full方法使用了不同的方法,但仍然没有将值传递给mainactivity。总是有一个空值?这就是它对我起作用的原因 最初是RegisterInGcm();高于parameterValue,但将其移到下面使其工作
//RegisterInGcm(); Wrong
string parameterValue = this.Intent.GetStringExtra("param");
if (parameterValue != null)
{
LoadApplication(new App(parameterValue));
}
else
{
LoadApplication(new App(null));
}
RegisterInGcm();
疯狂简单的改变,很多测试要做 这就是它对我起作用的原因 最初是RegisterInGcm();高于parameterValue,但将其移到下面使其工作
//RegisterInGcm(); Wrong
string parameterValue = this.Intent.GetStringExtra("param");
if (parameterValue != null)
{
LoadApplication(new App(parameterValue));
}
else
{
LoadApplication(new App(null));
}
RegisterInGcm();
疯狂简单的改变,很多测试要做 PendingEventFlags.UpdateCurrent应该可以工作。请访问查看更多信息
PendingEventFlags.UpdateCurrent应该可以工作。请访问查看更多信息
string parameterValue=this.Intent.GetStringExtra(“param”)
在onResume()生命周期函数中尝试此函数。string parameterValue=this.Intent.GetStringExtra(“param”)代码>在onResume()生命周期函数中尝试此函数。