Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement OneSignal push notification that opens URL in webview rather than browser?

How to open url in webview when onesignal push notification is send, right now it opens in the default browser and how to handle the target url by using notification handler. Here is the sample code where I want to implement onesignal notification and I tried my level best could not handle with it. Any suggestion from experts.

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        OneSignal.startInit(this).init();
}

handling

like image 781
Balaji JB Avatar asked Dec 06 '25 08:12

Balaji JB


1 Answers

Here is my implementation... I added this code in my Application class onCreate()

OneSignal.startInit(this).setNotificationOpenedHandler(new OneSignal.NotificationOpenedHandler() {
            @Override
            public void notificationOpened(OSNotificationOpenResult result) {

                String launchURL = result.notification.payload.launchURL;

                if (launchURL != null) {
                    Log.d(Const.DEBUG, "Launch URL: " + launchURL);

                    Intent intent = new Intent(getApplicationContext(), WebViewActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url", launchURL);
                    startActivity(intent);

                } else {
                    Log.d(Const.DEBUG, "Launch URL not found");

                    Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }
        }).init();
like image 183
Vamsi Challa Avatar answered Dec 08 '25 22:12

Vamsi Challa