OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

InApp URL intercept not working

Open d-aleksandrov opened this issue 6 years ago • 6 comments

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:

  1. add code
 OneSignal
            .startInit(this)
            .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
            .setInAppMessageClickHandler { action ->
                action.clickUrl = null
            }
            .unsubscribeWhenNotificationsAreDisabled(true)
            .init()
  1. send inapp with url
  2. click the url button

Anything else:

(crash stacktraces, as well as any other information here)

d-aleksandrov avatar May 21 '20 07:05 d-aleksandrov

@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.

jkasten2 avatar May 23 '20 21:05 jkasten2

I want to open url in special window or fragment based webview.

d-aleksandrov avatar May 25 '20 09:05 d-aleksandrov

also url can request an authorization request header or general user information

d-aleksandrov avatar May 25 '20 09:05 d-aleksandrov

@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 avatar Jun 02 '20 06:06 d-aleksandrov

@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

Jeasmine avatar Jun 23 '20 18:06 Jeasmine

Bad news. Thanks, trying to find the other way...

d-aleksandrov avatar Jun 30 '20 11:06 d-aleksandrov