私の考えはMessagingCenterと組み合わせてPutExtra
を利用するようにしました。
まず、あなたは通知バーに通知を示しています。MainActivity.csで
Intent intent = new Intent(Forms.Context, typeof(MainActivity));
if (openPage)
{
intent.SetFlags(ActivityFlags.SingleTop);
intent.PutExtra("OpenPage", "SomePage");
}
const int pendingIntentId = 0;
PendingIntent pendingIntent = PendingIntent.GetActivity(Forms.Context, pendingIntentId, intent, PendingIntentFlags.OneShot);
var nMgr = (NotificationManager)Android.App.Application.Context.GetSystemService(Context.NotificationService);
Notification.Builder notBuilder = new Notification.Builder(Android.App.Application.Context)
.SetContentIntent(pendingIntent)
.SetContentTitle("SomeApp")
.SetContentText(message)
.SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
.SetSmallIcon(Resource.Drawable.ic_launcher)
.SetAutoCancel(true);
var notification = notBuilder.Build();
nMgr.Notify(0, notification);
をあなたは余分なコンテンツをチェック:
protected override void OnNewIntent(Intent intent)
{
// Send message to the PCL (XF) if a certain page should be opened.
if (intent.HasExtra("OpenPage"))
{
string pageName = intent.GetStringExtra("OpenPage") ?? "None";
if (pageName != "None")
{
var message = new OpenPageMessage { PageName = pageName };
MessagingCenter.Send(message, Message.Msg_OpenPage);
}
}
base.OnNewIntent(intent);
}
そして、あなたの中央ナビゲーションインスタンス(例えばMainPage
)、このメッセージを購読する:
MessagingCenter.Subscribe<Message.OpenPageMessage>(this, Message.Msg_OpenPage, (async) message =>
{
// Loads a certain page if a message is received
switch (message.PageName)
{
case "SomePage":
await Navigation.PushModalAsync(new SomePage(), true);
break;
default:
break;
}
});
この
sourceの助けを借りて
public class Message
{
public const string Msg_OpenPage = "OpenPage";
public class OpenPageMessage {
public string PageName { get; set; }
}
}
:
はさらに、ここで私のMessage.csです。
編集
一度に複数のプッシュ通知を持っている場合はどこnotficationsどこ上書きの問題があります。異なるrequestCode
を使用するか、FLAG_UPDATE_CURRENT
を使用することができます。
こんにちは、ユーザーがプッシュ通知をクリックしている間に特定のページに移動するのに「余分なものを」使用しましたが、いくつかの状態は失敗します。私は2種類の通知、すなわち1.注文2.レビューを持っています。オーダータイプの通知には、追加するオーダーを追加し、レビュータイプの通知を受け取ったときに、追加するレビューを追加しましたが、オーダータイプの通知をクリックすると、「レビュー」エクストラが表示されます。最後の通知タイプが保存されます。どのようにそれを修正することができます。 – Deepak
私は、新しい質問を作成することをお勧めします。ここでは、(コードなどで)わかりやすく説明し、必要なものと問題の場所を記述します。通知タイプは1つしか使用していないため、現在問題を再現することはできません。 – testing
よろしくお願いいたします。 – Deepak