현재 성공적으로 수신 한 푸시 알림을 클릭 한 후 해당 페이지로 앱을 여는 중입니다. 내가 일하는 기초를 얻으면 Il은 id를 보내고있다. 어떤 이유로 ID가 알림을 탭한 후 ID가 주 활동으로 돌아가고 있지 않습니다.PutExtra xamarin 양식과 android를 사용하는 푸시 알림에서 주 활동으로 전달되지 않는 값
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);
}
}
다른 접근법을 사용한 전체 방법이지만 여전히 값은 주 활동으로 전달되지 않습니다. 항상 null이 있습니까?
'캐릭터가 parameterValue = this.Intent.GetStringExtra ("PARAM") 더 많은 참조하십시오. –