My app can open links by default using this:
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:scheme="http" />
<data
android:host="www.example.com"
android:scheme="http" />
....
Now, I have a link in my app that I do not support (yet). So what I am doing in the meanwhile is open it with an external browser. like this:
String requestURL = "www.example.com/unsupportedlink";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(requestURL));
mActivity.startActivity(i);
What I expect is that it will be open on the browser, but if the user chose that all links will be opened by app by default ("Allways open" and not "Just Once"), the app is called again and sends the link to the browser again - it causes infinite loop. How can I avoid this?
Android App Links, available on Android 6.0 (API level 23) and higher, are web links that use the HTTP and HTTPS schemes and contain the autoVerify attribute. This attribute allows your app to designate itself as the default handler of a given type of link.
Launch an url in an external browser app from your app. 1. Make sure the app has the INTERNET permission enabled in the manifest file. 2. Create a layout file for the WebView, activity_webview 3. Create the WebViewActivity.java 4. Launch the url within the app.
Android has a feature which allows the user to select a specific application to open a certain type of link. This feature can sometimes cause issues while opening URLs. Therefore, in this step, we will be resetting the system preferences.
Create an Android Project and replace the following layout file, activity_main.xml, and MainActivity.kt file. Run this Android Application, and click on any of the buttons, to open the respective URL separately in default Browser activity. In this Kotlin Android Tutorial, we learned how to open URL from Android Application in default browser.
Preferences Glitch: There is a feature in Android which allows the users to configure an application to be preferred when opening a certain type of link. This feature, however, has a glitch which triggers the “No App Found to Open URL” Error.
I found the answer:
Uri uri = Uri.parse(requestURL);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
context.startActivity(browserIntent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With