gpt4 book ai didi

android - 一个信号 |从通知负载获取 URL 并在自定义 WebView 中打开

转载 作者:太空狗 更新时间:2023-10-29 16:30:29 24 4
gpt4 key购买 nike

OneSignal 默认提供在浏览器中打开 URL 的功能。我想发送一个带有通知的 URL,在我创建的 WebView 中打开该 URL。我分享了我收到通知的位置的截图:

 class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
@Override
public void notificationReceived(OSNotification notification) {
JSONObject data = notification.payload.additionalData;
String customKey;

if (data != null) {
customKey = data.optString("customkey", null);
if (customKey != null)
Log.i("OneSignalExample", "customkey set with value: " + customKey);
}
}
}

我不确定如何在打开的推送中检索 URL 并在 WebView 中打开它。

最佳答案

SlashG 的回答对我很有帮助。这是我的实现...我在我的应用程序类 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();

关于android - 一个信号 |从通知负载获取 URL 并在自定义 WebView 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com