java - OneSignal SDK: How to open MainActivity after user taps on notification -


how can open main activity if user taps on push notification sent opensignal. wanted override default behaviour causing issue when app active. added following line per doc

<meta-data android:name="com.onesignal.notificationopened.default" android:value="disable" /> 

now if app closed, how can open mainactivity, , let execute notificationopenedhandler.

thank you.

if still want launcher / main activity open / resume when tapping on onesignal notification add following code activity intead.

private static boolean activitystarted;  @override protected void oncreate(bundle savedinstancestate) {   super.oncreate(savedinstancestate);    if (   activitystarted       && getintent() != null       && (getintent().getflags() & intent.flag_activity_reorder_to_front) != 0) {     finish();     return;   }    activitystarted = true; } 

see resume last activity when opening notification instructions more details.

if need more custom keep manifest entry noted above , add onesignal notificationopenedhandler onesignal.startinit in application class.

import com.onesignal.onesignal;  public class yourappclass extends application {    @override    public void oncreate() {       super.oncreate();        onesignal.startinit(this)         .setnotificationopenedhandler(new examplenotificationopenedhandler())         .init();    }    // fires when notification opened tapping on or 1 received while app running.   private class examplenotificationopenedhandler implements notificationopenedhandler {     @override     public void notificationopened(string message, jsonobject additionaldata, boolean isactive) {       // following can used open activity of choice.       /*       intent intent = new intent(getapplication(), youractivity.class);       intent.setflags(intent.flag_activity_reorder_to_front | intent.flag_activity_new_task);       startactivity(intent);       */       // follow instructions in link below prevent launcher activity starting.       // https://documentation.onesignal.com/docs/android-notification-customizations#changing-the-open-action-of-a-notification     } } 

see 4. add optional notificationopenedhandler more details on callback.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -