我的操作栏上有一个操作按钮,单击它会打开一个固定的 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/