Android: recognized as an App or Activity that can be made “default”

北城余情 提交于 2019-12-12 02:52:43

问题


When installed more than one Browser and the default is not set, I will get the chooser dialog with the possibility to set the default.

How does an application (or Activity) made itself recognizable by the system as a web browser. If I do something like this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(Intent.createChooser(intent, "TEST"));

I'll get a list of the apps: Browser (google), Contacts, Gmail, Phone, but not the Opera (mini) browser. So, Opera has no category Browsable but is still picked up by Android as a web browser. How does this work?


回答1:


It's achieved by adding appropriate <action> to <intent-filter> in your manifest file, so that Android knows what actions your app can perform and intents it can respond to.




回答2:


Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);

will bring up the browser chooser including the default checkbox. The data needs to be something of "http:" or "https:"-type.

Selecting an item in the dialog of course will open the browser going to the specified URL. And that is actually the case when at the base Home app when clicking to the browser icon.

This is not 100% what I hoped (100% would be open a browser without going to the URL), but acceptable.



来源:https://stackoverflow.com/questions/9000416/android-recognized-as-an-app-or-activity-that-can-be-made-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!