Hello,
Welcome to our Microsoft Q&A platform!
how can I test which part of the code is reached when the user clicks a push notification while the app is not even started yet. If in Visual Studio, I click Run button, the >app will already start and does not satisfy the test condition, i.e. the user clicks push notification when the app is not started.
If you want to test the Data messages
you need to the create your server environment and FCM, then you can send the FCM payload like following code.
{
"to":"some_device_token",
"content_available": true,
"notification": {
"title": "hello",
"body": "test message",
"click_action": "OPEN_ACTIVITY_1"
},
"data": {
"extra":"juice"
}
}
Then, after debug your application with VS, your application has been installed the emulator or device, you can click the application icon start this application. then click white background square.
choose your application, swipe up, to remove your application from running task, then you can set it(the user clicks push notification when the app is not started.)
===================
Update=======================
If the app is not yet started, and the user clicks push notification, how do I know what code gets executed so that I can modify code to let the desired page to appear? In this case, >when the user clicks push notification, the payload data should be sent somewhere in the code. Where is it?
First of all, I want to confirm with your nugetpackage, If you use CrossGeeks/FirebasePushNotificationPlugin, onMessageReceived()
callback even if your app is in foreground/background/killed. So you can receive the Data messages, If the app is not yet started.
However, if you use Xamarin.Firebase.Messaging
plugin (it comes from the native FCM lib by binding-library), Google official article do not mentioned that app is not yet started could receive the data messages, it just has two situation (Foreground and Background). See this Handling messages topic,
And you want to know "how do I know what code gets executed so that I can modify code to let the desired page to appear?". the notification is delivered to the device’s system tray, and the data payload is delivered in the extras of the intent of your launcher Activity., When app is in background, Intent must be delivered at your launcher activity . So it opens your Launcher activity. Now you check if there is data in Intent in launcher activity then start your required Activity like following code.
`
[Activity(Label = "FCMNotifications", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
if (Intent.Extras != null)
{
foreach (var key in Intent.Extras.KeySet())
{
var value = Intent.Extras.GetString(key);
if (string.Equals(value, "com.xamarin.fcmexample.OPEN_ACTIVITY_1"))
{
StartActivity(new Android.Content.Intent(this, typeof(SepcificalActivity)));
}
Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
}
}
}
`
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.