How to navigating to a specific page on Push Notification tap
I am developing firebase push notifications in Xamarin.Forms
using FirebasePushNotificationPlugin
. Somehow I am getting notifications for android project in Application
file, along with data
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data; //Dictionary type
};
Based on above data how can I navigate to specific Page
except MainPage()
?
This is my App.xaml.cs file in Shared project
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
MainActivity.cs class in Android project
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);
}
}
Edit 1:
According to @G.Hakim answer below code always opening NotificationsPage
without sending notification(Except first time. Only first time opening MainPage
when executing app). If I click on app it always goes to NotificationsPage
instead of 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();
}
}
c# firebase xamarin xamarin.forms firebase-cloud-messaging
|
show 2 more comments
I am developing firebase push notifications in Xamarin.Forms
using FirebasePushNotificationPlugin
. Somehow I am getting notifications for android project in Application
file, along with data
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data; //Dictionary type
};
Based on above data how can I navigate to specific Page
except MainPage()
?
This is my App.xaml.cs file in Shared project
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
MainActivity.cs class in Android project
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);
}
}
Edit 1:
According to @G.Hakim answer below code always opening NotificationsPage
without sending notification(Except first time. Only first time opening MainPage
when executing app). If I click on app it always goes to NotificationsPage
instead of 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();
}
}
c# firebase xamarin xamarin.forms firebase-cloud-messaging
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project'sPage
?
– CGPA6.4
Nov 27 '18 at 14:50
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
using thisglobal::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!
– G.hakim
Nov 28 '18 at 6:13
|
show 2 more comments
I am developing firebase push notifications in Xamarin.Forms
using FirebasePushNotificationPlugin
. Somehow I am getting notifications for android project in Application
file, along with data
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data; //Dictionary type
};
Based on above data how can I navigate to specific Page
except MainPage()
?
This is my App.xaml.cs file in Shared project
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
MainActivity.cs class in Android project
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);
}
}
Edit 1:
According to @G.Hakim answer below code always opening NotificationsPage
without sending notification(Except first time. Only first time opening MainPage
when executing app). If I click on app it always goes to NotificationsPage
instead of 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();
}
}
c# firebase xamarin xamarin.forms firebase-cloud-messaging
I am developing firebase push notifications in Xamarin.Forms
using FirebasePushNotificationPlugin
. Somehow I am getting notifications for android project in Application
file, along with data
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
var data = p.Data; //Dictionary type
};
Based on above data how can I navigate to specific Page
except MainPage()
?
This is my App.xaml.cs file in Shared project
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
MainActivity.cs class in Android project
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);
}
}
Edit 1:
According to @G.Hakim answer below code always opening NotificationsPage
without sending notification(Except first time. Only first time opening MainPage
when executing app). If I click on app it always goes to NotificationsPage
instead of 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();
}
}
c# firebase xamarin xamarin.forms firebase-cloud-messaging
c# firebase xamarin xamarin.forms firebase-cloud-messaging
edited Nov 28 '18 at 15:00
CGPA6.4
asked Nov 27 '18 at 14:19
CGPA6.4CGPA6.4
2,85621031
2,85621031
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project'sPage
?
– CGPA6.4
Nov 27 '18 at 14:50
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
using thisglobal::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!
– G.hakim
Nov 28 '18 at 6:13
|
show 2 more comments
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project'sPage
?
– CGPA6.4
Nov 27 '18 at 14:50
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
using thisglobal::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!
– G.hakim
Nov 28 '18 at 6:13
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project's
Page
?– CGPA6.4
Nov 27 '18 at 14:50
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project's
Page
?– CGPA6.4
Nov 27 '18 at 14:50
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
using this
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!– G.hakim
Nov 28 '18 at 6:13
using this
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!– G.hakim
Nov 28 '18 at 6:13
|
show 2 more comments
2 Answers
2
active
oldest
votes
It's actually very simple you can do it using some trickery:
First, call the MainActivity from your notification so that you can use the existing xamarin forms loading functionality.
Then maintain a bool on your App class constructor something like this:
public App(bool hasNotification=false,object notificationData=null)
{
if(hasNotification)
{//case where you receive a notification} // call your normal functionality here
else
{//case where you do not recieve a notification} // notification functionality here
}
Now here is the trick that steals the show, When you receive a notification in your MainActivity pass the bool as true in the load app method and pass the data if anything is present in the notification.Something like this:
LoadApplication(new App(true,*yourData*))
Note: I have defined the optional parameter in the constructor so you can even use the empty app constructor to make it work;
Update:
private bool IsNotification=false;
private object NotificationData;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
NotificationData = p.Data;
IsNotification=false;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
};
if(IsNotification)
LoadApplication(new App(IsNotification,NotificationData));
else
LoadApplication(new App());
}
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call thisFirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.
– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
add a comment |
This issue has been solved by sending color
key from notification payload
.
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
if (p.Data.ContainsKey("color"))
{
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NotificationsPage()
{
BackgroundColor = Color.FromHex($"{p.Data["color"]}")
});
});
}
};
Note: Above code is working when app open & in background. Not working for foreground. For more information visit this ticket.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501739%2fhow-to-navigating-to-a-specific-page-on-push-notification-tap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's actually very simple you can do it using some trickery:
First, call the MainActivity from your notification so that you can use the existing xamarin forms loading functionality.
Then maintain a bool on your App class constructor something like this:
public App(bool hasNotification=false,object notificationData=null)
{
if(hasNotification)
{//case where you receive a notification} // call your normal functionality here
else
{//case where you do not recieve a notification} // notification functionality here
}
Now here is the trick that steals the show, When you receive a notification in your MainActivity pass the bool as true in the load app method and pass the data if anything is present in the notification.Something like this:
LoadApplication(new App(true,*yourData*))
Note: I have defined the optional parameter in the constructor so you can even use the empty app constructor to make it work;
Update:
private bool IsNotification=false;
private object NotificationData;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
NotificationData = p.Data;
IsNotification=false;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
};
if(IsNotification)
LoadApplication(new App(IsNotification,NotificationData));
else
LoadApplication(new App());
}
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call thisFirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.
– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
add a comment |
It's actually very simple you can do it using some trickery:
First, call the MainActivity from your notification so that you can use the existing xamarin forms loading functionality.
Then maintain a bool on your App class constructor something like this:
public App(bool hasNotification=false,object notificationData=null)
{
if(hasNotification)
{//case where you receive a notification} // call your normal functionality here
else
{//case where you do not recieve a notification} // notification functionality here
}
Now here is the trick that steals the show, When you receive a notification in your MainActivity pass the bool as true in the load app method and pass the data if anything is present in the notification.Something like this:
LoadApplication(new App(true,*yourData*))
Note: I have defined the optional parameter in the constructor so you can even use the empty app constructor to make it work;
Update:
private bool IsNotification=false;
private object NotificationData;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
NotificationData = p.Data;
IsNotification=false;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
};
if(IsNotification)
LoadApplication(new App(IsNotification,NotificationData));
else
LoadApplication(new App());
}
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call thisFirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.
– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
add a comment |
It's actually very simple you can do it using some trickery:
First, call the MainActivity from your notification so that you can use the existing xamarin forms loading functionality.
Then maintain a bool on your App class constructor something like this:
public App(bool hasNotification=false,object notificationData=null)
{
if(hasNotification)
{//case where you receive a notification} // call your normal functionality here
else
{//case where you do not recieve a notification} // notification functionality here
}
Now here is the trick that steals the show, When you receive a notification in your MainActivity pass the bool as true in the load app method and pass the data if anything is present in the notification.Something like this:
LoadApplication(new App(true,*yourData*))
Note: I have defined the optional parameter in the constructor so you can even use the empty app constructor to make it work;
Update:
private bool IsNotification=false;
private object NotificationData;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
NotificationData = p.Data;
IsNotification=false;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
};
if(IsNotification)
LoadApplication(new App(IsNotification,NotificationData));
else
LoadApplication(new App());
}
It's actually very simple you can do it using some trickery:
First, call the MainActivity from your notification so that you can use the existing xamarin forms loading functionality.
Then maintain a bool on your App class constructor something like this:
public App(bool hasNotification=false,object notificationData=null)
{
if(hasNotification)
{//case where you receive a notification} // call your normal functionality here
else
{//case where you do not recieve a notification} // notification functionality here
}
Now here is the trick that steals the show, When you receive a notification in your MainActivity pass the bool as true in the load app method and pass the data if anything is present in the notification.Something like this:
LoadApplication(new App(true,*yourData*))
Note: I have defined the optional parameter in the constructor so you can even use the empty app constructor to make it work;
Update:
private bool IsNotification=false;
private object NotificationData;
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
FirebasePushNotificationManager.ProcessIntent(this, Intent);
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
NotificationData = p.Data;
IsNotification=false;
DependencyService.Get<IToast>().DisplayTost("opened notifications");
};
if(IsNotification)
LoadApplication(new App(IsNotification,NotificationData));
else
LoadApplication(new App());
}
edited Nov 29 '18 at 6:03
answered Nov 28 '18 at 7:06
G.hakimG.hakim
4,58611033
4,58611033
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call thisFirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.
– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
add a comment |
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call thisFirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.
– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Thanks for your answer. I'll revert.
– CGPA6.4
Nov 28 '18 at 7:09
Oh yeah, one more thing I think you need to call this
FirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.– G.hakim
Nov 28 '18 at 7:10
Oh yeah, one more thing I think you need to call this
FirebasePushNotificationManager.ProcessIntent(this, Intent);
before the load application method.– G.hakim
Nov 28 '18 at 7:10
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
Your code always opening NotificationPage without sending notification, when I tap on App icon. For more information check my edits.
– CGPA6.4
Nov 28 '18 at 15:01
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I have edited my answer with how the code should be take a look
– G.hakim
Nov 28 '18 at 20:06
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
I appreciate your help. However this issue was related to plugin not our code. I have posted answer have a look. Thanks a lot.
– CGPA6.4
Dec 1 '18 at 9:07
add a comment |
This issue has been solved by sending color
key from notification payload
.
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
if (p.Data.ContainsKey("color"))
{
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NotificationsPage()
{
BackgroundColor = Color.FromHex($"{p.Data["color"]}")
});
});
}
};
Note: Above code is working when app open & in background. Not working for foreground. For more information visit this ticket.
add a comment |
This issue has been solved by sending color
key from notification payload
.
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
if (p.Data.ContainsKey("color"))
{
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NotificationsPage()
{
BackgroundColor = Color.FromHex($"{p.Data["color"]}")
});
});
}
};
Note: Above code is working when app open & in background. Not working for foreground. For more information visit this ticket.
add a comment |
This issue has been solved by sending color
key from notification payload
.
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
if (p.Data.ContainsKey("color"))
{
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NotificationsPage()
{
BackgroundColor = Color.FromHex($"{p.Data["color"]}")
});
});
}
};
Note: Above code is working when app open & in background. Not working for foreground. For more information visit this ticket.
This issue has been solved by sending color
key from notification payload
.
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
if (p.Data.ContainsKey("color"))
{
Device.BeginInvokeOnMainThread(() =>
{
Xamarin.Forms.Application.Current.MainPage.Navigation.PushModalAsync(new NotificationsPage()
{
BackgroundColor = Color.FromHex($"{p.Data["color"]}")
});
});
}
};
Note: Above code is working when app open & in background. Not working for foreground. For more information visit this ticket.
edited Dec 1 '18 at 9:13
answered Dec 1 '18 at 9:05
CGPA6.4CGPA6.4
2,85621031
2,85621031
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53501739%2fhow-to-navigating-to-a-specific-page-on-push-notification-tap%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You need to do it natively
– G.hakim
Nov 27 '18 at 14:46
@G.hakim - I have implemented notifications for Xamarin.android still confused how can I do that in a way so that it would combine easily with Forms. If I am opening Activity1 navitely, how it relates to shared project's
Page
?– CGPA6.4
Nov 27 '18 at 14:50
Well initialize your Xamarin forms page in Activity1 and then just push to the page that you want to navigate to.
– G.hakim
Nov 27 '18 at 15:48
How to push page after initializing activity?
– CGPA6.4
Nov 28 '18 at 6:11
using this
global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App());
if you want i can post an example!!– G.hakim
Nov 28 '18 at 6:13