Open the link in the browser instead of the default app.

I am creating an app for a site and I have created a redirect link activity (only for the url http: //*.domain.com) that redirect to the activity if the url is supported. If support shouldn't open in browser. It works fine, but when the user configures the default app for the app by clicking the always button in the action list, the app goes into a loop. opening an activity, checking for link support, if the intention of opening with a flag is not supported Intent.ACTION_VIEW

, then the activity is reopened.

Question: How do I open a link in a browser (probably the default) instead of my app, which sets the default for the URL.

My method that I am trying to open the url in the browser:

private void unsupportedLink() {
    Toast.makeText(this, R.string.unsupported_link, Toast.LENGTH_LONG).show();
    Intent openUrl = new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()));
    startActivity(openUrl);
    finish();
}

      

Activity in manifest:

<activity
            android:name=".util.UrlHandler"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Translucent.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />


                <data
                    android:scheme="http"
                    android:pathPattern="/.*"
                    android:host="m.domain.com" />
                <data
                    android:scheme="http"
                    android:pathPattern="/.*"
                    android:host="www.domain.com" />
            </intent-filter>
        </activity>

      

+3


source to share





All Articles