简体   繁体   中英

I don't want my app to appear on the chooser dialog when opening URL's

I have an action button on my action bar that opens a fixed url when clicked, it works fine, but I dont want my own app to appear on the chooser dialog "complete action using", it should just appears the phone default browsers (like Chrome or Mozilla), actually It appears Chrome and my app as options to open the url. I implemented this code from here: http://developer.android.com/intl/es/guide/components/intents-common.html

This is my code:

//Manifest.xml

<activity
        android:name="pepubli.com.Controlador.Ciudad_Escogida"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="http"/>
            <category android:name="android.intent.category.DEFAULT" />
            <!-- The BROWSABLE category is required to get links from web 
            pages. -->
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity> 

//Ciudad_Escogida.Java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if(item.getItemId() == R.id.web_page){

        Uri webpage = Uri.parse("http://www.pepubli.com");
        Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
        if (intent.resolveActivity(getPackageManager()) != null) {
            startActivity(intent);
        }

    }
    return super.onOptionsItemSelected(item);
}

remove this line from your application manifest.

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

also remove

<data android:scheme="http"/>

and replace

<action android:name="android.intent.action.VIEW" />

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

to

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

so your intent filter should be like

  <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM