InApp URL intercept not working
Description:
I'm trying intercept incorrect url's in app, but webview always showed. my code
OneSignal
.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setInAppMessageClickHandler { action ->
action
?.clickUrl
?.takeIf { it.startsWith(Constants.URL_WEB, ignoreCase = true) }
?.let(::openInAppUrl)
action.clickUrl = null
}
.unsubscribeWhenNotificationsAreDisabled(true)
.init()
Probably library always call intent automaticallly. Custom click handler firePublicClickHandler calls with delay but fireClickActionhandler calls more later than it.
code in library
void onMessageActionOccurredOnPreview(@NonNull final OSInAppMessage message, @NonNull final JSONObject actionJson) throws JSONException {
final OSInAppMessageAction action = new OSInAppMessageAction(actionJson);
action.firstClick = message.takeActionAsUnique();
firePublicClickHandler(action);
beginProcessingPrompts(message, action.prompts);
fireClickAction(action);
logInAppMessagePreviewActions(action);
}
Environment
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.7'
implementation 'com.onesignal:OneSignal:3.13.2'
Steps to Reproduce Issue:
- add code
OneSignal
.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.setInAppMessageClickHandler { action ->
action.clickUrl = null
}
.unsubscribeWhenNotificationsAreDisabled(true)
.init()
- send inapp with url
- click the url button
Anything else:
(crash stacktraces, as well as any other information here)
@d-aleksandrov Thanks for the details.
Limitation
Unfortunately if you modify the action from the callback you pass to setInAppMessageClickHandler it won't have any effect on other logic in the OneSignal SDK.
This is due to the callback running on a different thread:
https://github.com/OneSignal/OneSignal-Android-SDK/blob/39691a9569fbdb1ae7f869a1b908fbf9ce9d0f5c/OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageController.java#L372-L387
Issue Being Solved
From a high level I am not sure I understand the issue you are trying to solve? You noted that "I'm trying intercept incorrect url's in app..." however I don't understand why there would be any incorrect URLs set on your In-App Message. Since In-App Messages are created via the OneSignal dashboard can you verify you have them correct before saving there?
Future
Being able to modify the action object would provide more flexibility and I can see it being a powerful feature. We will consider this as I could see some useful use cases suchs a runtime variable substitution into a URL as one example.
I want to open url in special window or fragment based webview.
also url can request an authorization request header or general user information
@jkasten2 is it possible to realize? It's a really important feature for business. Now I'm trying to organize pushes in my project. Ability to recognize and block not actual inapps is very important for me
@d-aleksandrov I don't know if you are still with this problem, but you can't intercept the InAppMessage. If you want to open an URL on a special window you can send a silent notification and managed it by yourself. But IAM probably is not the solution you are searching for. I hope that helps! Sorry for the delay
Bad news. Thanks, trying to find the other way...