簡體   English   中英

我不希望我的應用在打開URL時出現在選擇器對話框中

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

我在操作欄上有一個操作按鈕,當單擊該按鈕時會打開一個固定的url,它可以正常工作,但是我不希望自己的應用程序出現在選擇器對話框“使用完整操作”中,它應該只顯示手機默認的瀏覽器(例如Chrome或Mozilla),實際上它似乎是Chrome和我的應用程序作為打開URL的選項。 我從這里實現了以下代碼: http : //developer.android.com/intl/es/guide/components/intents-common.html

這是我的代碼:

//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);
}

從您的應用清單中刪除此行。

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

也刪除

<data android:scheme="http"/>

並更換

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

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

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

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

所以你的意圖過濾器應該像

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM