java - 我不希望我的应用在打开 URL 时出现在选择器对话框中

标签 java android xml

我的操作栏上有一个操作按钮,单击它会打开一个固定的 url,它工作正常,但我不希望我自己的应用程序出现在选择器对话框“使用完成操作”中,它应该只显示手机默认值浏览器(如 Chrome 或 Mozilla),实际上它显示 Chrome 和我的应用程序作为打开 url 的选项。我从这里实现了这段代码:http://developer.android.com/intl/es/guide/components/intents-common.html

这是我的代码:

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

最佳答案

从您的应用程序 list 中删除这一行。

 <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 过滤器应该是这样的

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

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

关于java - 我不希望我的应用在打开 URL 时出现在选择器对话框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36930778/

相关文章:

java - Gradle:正则表达式查找并替换特定文本周围的空格

Android 小部件,重启后它没有显示

PHP - 从多个 MySQL 查询创建 XML 并按日期排序

xml - xslt模板优化

java - 在JOptionPane InputDialog中找到Ok

java - 如何在上下文初始化后创建 session bean

android - 如何禁用Android应用程序的通知栏?

android - eclipse : Specify multiple res directories like specifying multiple src directories

PHP DOM 操作

java - 使用 Java 在 Eclipse 中创建扫描仪时出现 FileNotFoundException