1

Hello i use a tamplate to send notifications to users.

All works fine. When the user press the notification then the notification open with the browser.

How i could open this with the webview of the application?

 // This fires when a notification is opened by tapping on it or one is received while the app is running.
class NotificationHandler implements OneSignal.NotificationOpenedHandler {
    // This fires when a notification is opened by tapping on it.
    @Override
    public void notificationOpened(OSNotificationOpenResult result) {
        try {
            JSONObject data = result.notification.payload.additionalData;
            if (data != null) {
                String url = data.optString("url", null);
                if (url != null) {
                    //If the app is not on foreground, clicking the notification will start the app, and push_url will be used.
                    Intent browserIntent;
                    //if (!result.notification.isAppInFocus) {
                        browserIntent = new Intent(App.this, WebviewActivity.class);
                        browserIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                        browserIntent.putExtra(WebviewActivity.OPEN_EXTERNAL, Config.OPEN_INLINE_EXTERNAL);
                        browserIntent.putExtra(WebviewActivity.URL, result.notification.payload.additionalData.getString("url"));
                        android.util.Log.v("INFO", "Received notification while app was on background");
                   // } else { //If the app is in foreground, don't interup the current activities, but open webview in a new window.
                   //     browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.notification.payload.additionalData.getString("url")));
                   //     browserIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                   //     android.util.Log.v("INFO", "Received notification while app was on foreground");
                   // }
                    startActivity(browserIntent);
                }
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }

}
George Ch
  • 53
  • 1
  • 10
  • You could simply extract URL from the received intent in `WebviewActivity `and use it in `webview.loadUrl()` call. – j2ko Mar 06 '17 at 13:30
  • how i can do this? – George Ch Mar 06 '17 at 13:44
  • You know how to create intent and start activity but don't know hpw to handle incomming intent? Are you the author of the code above? – j2ko Mar 06 '17 at 13:46
  • @j2ko thanks for reply. no. im not the author. this is a paid template but the author doesnt support any change like this – George Ch Mar 06 '17 at 13:53
  • So looks like this is off-topic. You could learn about handling of Intents here : http://stackoverflow.com/questions/5265913/how-to-use-putextra-and-getextra-for-string-data and here : https://developer.android.com/training/sharing/receive.html – j2ko Mar 06 '17 at 14:04
  • Possible duplicate of [How to send dynamic data from one activity to another in android](http://stackoverflow.com/questions/24967667/how-to-send-dynamic-data-from-one-activity-to-another-in-android) – j2ko Mar 06 '17 at 14:06

0 Answers0