0

Notifications open in the browser, I want to open the webview. How can I open OneSignal notifications in WebView, thanks

Here is code in MainActivity

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(), MainActivity.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(), MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
}).init();

1 Answers1

0

Instead of passing the URL to the MainActivity just create a new activity with a webview and pass the URL there.

Akash Popat
  • 420
  • 3
  • 18