Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Open url in external browser causes an infinite loop

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?

like image 987
Uriel Frankel Avatar asked Apr 09 '14 09:04

Uriel Frankel


People also ask

What are supported links in apps?

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.

How to launch an external URL in an external browser app?

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.

Why can’t I open URLs in Android?

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.

How to open URL from Android application in default browser activity?

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.

What causes “no app found to open url” error?

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.


1 Answers

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);
like image 184
Uriel Frankel Avatar answered Oct 02 '22 00:10

Uriel Frankel