LocalNotification plugin integration

LocalNotification plugin integration

  
I have been trying to add local notification plugin to my Outsystems app. I have used https://github.com/katzer/cordova-plugin-local-notifications plugin for the same. It is working fine and I am getting reminders as expected.

Now I want to redirect to a page in O/S app  from reminder notification not just launch the app. Any suggestion/thoughts how this could be done? 

Thanks
Rajni
Hello Rajni,

Quickly looking at the plugin documentation, seems like the best way is to store the URL you want to open on the  "json" option of the notification and then implement window.plugin.notification.local.onclick to open the window on the URL provided on the json option. Does that make sense?

Best of luck,
Rodrigo
Hi Rodrigo, 


On tapping the notification, i want to open up a page and get the json payload into it. Then, within its prepare want to perform some logic and then redirect to a different page.  Since the target url is not fixed/predetermined, i cannot use the approach you had mentioned.
 
Ex: Lets assume that i get a type_id and item_id in the json payload. i want to do a lookup to get item details and then redirect to the details page based on the type_id. 
 
Thanks
Hello Rajni,

I investigated how this could be done in android, and you'll need to edit the plugin in order to send the extra information to the notification. In particular, you need to go to the "onCreate" function on the "ReceiverActivity.java" file from the plugin and change the code to send "bundle" to "launchMainIntent". You'll need to change the signature of the function to "launchMainIntent (Bundle bundle)".

Next, change the launchIntent to send the bundle:
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName).putExtras(bundle);

You can now edit "SplashScreen.java", and change the "onCreate" function to do whatever you want. To test:

Bundle xtras = getIntent().getExtras();
if (xtras != null) {
    EventLogger.logMessage(getClass(), "Got a notification!");
}
You can read the values by using: xtras.getString("LOCAL_NOTIFICATION_OPTIONS")

This is how far I managed to go, considering this is beyond our support for OutSystems Now :-) but I hope it's enough to get you on the right track.

Cheers,
Rodrigo
Thanks Rodrigo. This is a good approach to get the data from notification into an android activity.

What we actually need is to get the data into the OutSystems app on a page. We will need the data to be passed to a web page on the Outsystems mobile app.
Hi Loki,

The way to do that is to call a URL with the necessary arguments. Like I explained above, you can edit "SplashScreen.java", and change the "onCreate" function to add something like:

if (xtras != null) {
	registerReceivers();
	Intent intent = new Intent(getApplicationContext(), WebApplicationActivity.class); 
	Application application = new Application("App", 0, "App desc");
	application.setPath("OSNowTests/NotificationDest.aspx?Number=3");
	intent.putExtra(WebApplicationActivity.KEY_APPLICATION, application);
	startActivity(intent);
	return;
}

On the example, the URL is fixed, but you can use the parameters you get from the notification to build the path.

Best of luck!
Rodrigo