5

I'm creating app for site and i created link redirector activity(for http://*.domain.com urls only), that redirect to activity if url support. If not support should open link in browser. It's working ok, but when user setting app default app, clicking always button in activity chooser, app goes to loop. activity opening, checking link support, if not support opening intent with Intent.ACTION_VIEW flag then activity opens again.

Question : How to open link in browser (may be default), instead of my app, that set default for url.

My method that i trying open url in 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>
alashow
  • 2,735
  • 3
  • 21
  • 47
  • 1
    Unfortunately there's no direct way to do that. You can get a list of apps which can handle something, and exclude yourself from it, but if there are multiple other candidates you'd still have to choose one... – Chris Stratton Oct 21 '14 at 19:37
  • `"If not support should open link in browser."` How do you determine if your app supports the URL or not? – Code-Apprentice Oct 21 '14 at 19:43
  • @Code-Apprentice shortly, by url parameters. I'm parsing url, for example if url domain.com/index.php?q=users support, else if domain.com/index.php?q=chat not support – alashow Oct 21 '14 at 19:47

0 Answers0