現在、正常に受信したプッシュ通知をクリックした後、特定のページにアプリを開くことを目指しています。私は一度基本を働かせたら、私はイドを送るだろう。何らかの理由で、通知がタップされた後、主活動にIDが戻されていない。PutExtra xamarinフォームとアンドロイドを使用したプッシュ通知からmainactivityに渡されない値
BroadcastRecieverクラスプッシュ通知を送信する
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));
}
は非常に簡単であると思われるが、私のパラメータ値は常にnull任意の考えのおかげで
UPDATE
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);
}
}
異なる方法で完全なメソッドを使用していますが、値が主なアクティビティに渡されることはありません。常にヌルがありますか?
'文字列parameterValue = this.Intent.GetStringExtra( "PARAM")で詳細を参照してください;' 'onResume()'ライフサイクル機能で、この機能を試してみてください。 –