Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Uri exclusion list for making some redirect URI to be considered as Universal Links #1111

Open
b-phygtl opened this issue Oct 22, 2024 · 4 comments

Comments

@b-phygtl
Copy link

Hello,

We have been using the Gree plugin for unity for both Android and iOS. One of the things we encountered is that our redirect URIs are Universal Links(iOS) / Deeplinks(Android). That means whenever we encounter such links we would like to have the Android/iOS to trigger an Intent/Activity respectively on each platform.
Currently Gree plugin opens the redirect Uri on the webview itself and we'd like to have Gree create the Intent/Activity calls for platforms.

For that I have modified the plugin to provide an API where one could add an Uri to an exclusion list and whenever there is an Uri with Protocol://your.domainname.com/ comes in it'd call the deeplink in the phone.

I want to create a pull request for your review. I was wondering if you have any suggestion or recommendation to handle this scenario. Please let me know.

@KojiNakamaru
Copy link
Member

Have you looked SetURLPattern()? #550 shows its brief usage.

@b-phygtl
Copy link
Author

b-phygtl commented Oct 22, 2024

Yes, I had taken a look at this before.

I do have a question on that.
If I add the redirect URI into the Deny pattern, does the Gree Webview creates an Intent or it gives a call back to the hooked function ?
The reason I asked this is because the SetURLPattern() doesnt seem to create an Intent on Android(as well as in iOS) since the

public boolean shouldOverrideUrlLoading(WebView view, String url) {
canGoBack = webView.canGoBack();
canGoForward = webView.canGoForward();
boolean pass = true;
if (mAllowRegex != null && mAllowRegex.matcher(url).find()) {
pass = true;
} else if (mDenyRegex != null && mDenyRegex.matcher(url).find()) {
pass = false;
}
if (!pass) {
return true;
}
if (url.startsWith("unity:")) {
String message = url.substring(6);
mWebViewPlugin.call("CallFromJS", message);
return true;
} else if (mHookRegex != null && mHookRegex.matcher(url).find()) {
mWebViewPlugin.call("CallOnHooked", url);
return true;
} else if (!url.toLowerCase().endsWith(".pdf")
&& !url.startsWith("https://maps.app.goo.gl")
&& (url.startsWith("http://")
|| url.startsWith("https://")
|| url.startsWith("file://")
|| url.startsWith("javascript:"))) {
mWebViewPlugin.call("CallOnStarted", url);
// Let webview handle the URL
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// PackageManager pm = a.getPackageManager();
// List apps = pm.queryIntentActivities(intent, 0);
// if (apps.size() > 0) {
// view.getContext().startActivity(intent);
// }
try {
view.getContext().startActivity(intent);
} catch (ActivityNotFoundException ex) {
}
return true;
}

It looks like it returns true. Where I was expecting that Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); will be called for deeplink calls.

@KojiNakamaru
Copy link
Member

The deny pattern simply denies a matched request. I guess you can utilize the hooked pattern instead. When a url is hooked, you can receive it with the hooked callback and open it by Application.OpenURL().

@b-phygtl
Copy link
Author

I see ! The webview gives me a callback on when an Url is hooked. Let me try that.

Appreciate the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants