Я разрабатываю push-уведомления Firebase в Xamarin.Forms
, используя FirebasePushNotificationPlugin
.Каким-то образом я получаю уведомления для проекта Android в файле Application
вместе с данными
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data; //Dictionary type
};
На основе приведенных выше данных, как я могу перейти к конкретному Page
кроме MainPage()
?
Это мой файл App.xaml.cs в общем проекте
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
Класс MainActivity.cs в проекте Android
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
FirebasePushNotificationManager.ProcessIntent(this, Intent);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
FirebasePushNotificationManager.ProcessIntent(this, intent);
}
}
Редактировать 1 : Согласно @G.Хаким ответом ниже код всегда открывает NotificationsPage
без отправки уведомления (За исключением первого раза. Только при первом открытии MainPage
при запуске приложения).Если я нажимаю на приложение, оно всегда отображается как NotificationsPage
вместо MainPage
.
MainActivity.cs
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App(false,null));
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
LoadApplication(new App(true, p));
};
}
App.xaml.cs
public App(bool hasNotification = false, object notificationData = null)
{
if (hasNotification)
{
MainPage = new NotificationsPage();
}
else
{
MainPage = new MainPage();
}
}