Android 在webview中打开onesignal通知
您好,我使用tamplate向用户发送通知 一切正常。 当用户按下通知时,通知将通过浏览器打开 如何使用应用程序的webview打开此应用程序Android 在webview中打开onesignal通知,android,webview,Android,Webview,您好,我使用tamplate向用户发送通知 一切正常。 当用户按下通知时,通知将通过浏览器打开 如何使用应用程序的webview打开此应用程序 // This fires when a notification is opened by tapping on it or one is received while the app is running. class NotificationHandler implements OneSignal.NotificationOpenedHandle
// 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();
}
}
}
您只需在
WebviewActivity
中从接收到的意图中提取URL,并在webview.loadUrl()调用中使用它。我如何做到这一点?您知道如何创建意图并启动活动,但不知道hpw如何处理输入意图?您是上述代码的作者吗?@j2ko感谢您的回复。不,我不是作者。这是一个付费模板,但作者不支持这样的任何更改,所以看起来这是离题的。您可以在这里了解意图的处理:在这里:您可以简单地从WebviewActivity
中收到的意图中提取URL,并在webview.loadUrl()
call中使用它。我如何做到这一点?您知道如何创建意图并启动活动,但不知道hpw如何处理输入意图?您是上述代码的作者吗?@j2ko感谢您的回复。不,我不是作者。这是一个付费模板,但作者不支持这样的任何更改,所以看起来这是离题的。您可以在这里了解意图的处理:这里: