在 android 中的默认浏览器选择列表中添加我的浏览器?
Add my browser in the default browser selection list in android?
遵循 How to add my browser in the default browser selection list in android? 的建议。我在 manifest
文件中指定了我的 Intent
:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
我也添加了权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
但我的浏览器仍然没有显示在设置中浏览器类别的默认应用程序选项中。
我是否需要执行任何其他操作才能使我的应用显示在浏览器的默认选项中?
尝试将 <category android:name="android.intent.category.BROWSABLE" />
包含在目标 activity 的 intent-filter
中,如 developer documentation 所说:
If the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the BROWSABLE
category, so that only activities supporting this category will be considered as possible actions.
为了使 intent-filter
可以从可点击的 link 访问,这是必需的。没有它,单击 link 无法解析到您的应用程序。
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
.
附加提示:(如果您想强制您的应用成为默认浏览器)
Android App Links Android 6.0(API 级别 23)及更高版本允许应用程序将自己指定为给定类型 link 的默认处理程序。如果用户不希望该应用成为默认处理程序,他们可以从其设备的系统设置中覆盖此行为。
要为您的应用启用 link 处理验证,请在 intent-filter
标签中设置 android:autoVerify="true"
:
<activity ...>
<intent-filter android:autoVerify="true">
...
</intent-filter>
</activity>
您可以通过 Activity
Browsable.using 在 Android 清单文件中的代码下方使用 Intent-Filter
来实现。
您可以使用 Launcher
Activity。
<activity android:name="BrowsableActivity">
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent_filter>
</activity>
并且您必须提供 scheme
作为 http
和 https
才能使用您的应用程序打开链接。
如文档中所述 developer.android.com
您需要如下设置 intent filer
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!-- Include the host attribute if you want your app to respond
only to URLs with your app's domain. -->
<data android:scheme="http" android:host="www.example.com" />
<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>
您需要考虑可能适用的各种情况。
请参考下面的意图过滤器。最后还提供 link 。
<activity android:name="BrowserActivity"
android:label="@string/application_name"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/BrowserTheme"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- For these schemes were not particular MIME type has been
supplied, we are a good candidate. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<!-- For these schemes where any of these particular MIME types
have been supplied, we are a good candidate. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="inline" />
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
</intent-filter>
<!-- We are also the main entry point of the browser. -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- The maps app is a much better experience, so it's not
worth having this at all... especially for a demo!
<intent-filter android:label="Map In Browser">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/postal-address" />
</intent-filter>
-->
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
查看您可能需要的不同类型的意图过滤器,以涵盖所有可能的情况。
参考这个link - froyo 浏览器的完整清单文件。
考虑将 CATEGORY_APP_BROWSER
与您的主过滤器一起使用:
Used with ACTION_MAIN
to launch the browser application. The activity should be able to browse the Internet.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_BROWSER" />
</intent-filter>
您可以通过编程方式实现此目的,如下所示:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.setPackage("your.app.package.name");
startActivity(share);
如果您在 phone 上检查应用程序是否存在,那也很好。
快乐编码:)
遵循 How to add my browser in the default browser selection list in android? 的建议。我在 manifest
文件中指定了我的 Intent
:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
我也添加了权限:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
但我的浏览器仍然没有显示在设置中浏览器类别的默认应用程序选项中。
我是否需要执行任何其他操作才能使我的应用显示在浏览器的默认选项中?
尝试将 <category android:name="android.intent.category.BROWSABLE" />
包含在目标 activity 的 intent-filter
中,如 developer documentation 所说:
If the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the
BROWSABLE
category, so that only activities supporting this category will be considered as possible actions.
为了使 intent-filter
可以从可点击的 link 访问,这是必需的。没有它,单击 link 无法解析到您的应用程序。
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
.
附加提示:(如果您想强制您的应用成为默认浏览器)
Android App Links Android 6.0(API 级别 23)及更高版本允许应用程序将自己指定为给定类型 link 的默认处理程序。如果用户不希望该应用成为默认处理程序,他们可以从其设备的系统设置中覆盖此行为。
要为您的应用启用 link 处理验证,请在 intent-filter
标签中设置 android:autoVerify="true"
:
<activity ...>
<intent-filter android:autoVerify="true">
...
</intent-filter>
</activity>
您可以通过 Activity
Browsable.using 在 Android 清单文件中的代码下方使用 Intent-Filter
来实现。
您可以使用 Launcher
Activity。
<activity android:name="BrowsableActivity">
<intent_filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent_filter>
</activity>
并且您必须提供 scheme
作为 http
和 https
才能使用您的应用程序打开链接。
如文档中所述 developer.android.com
您需要如下设置 intent filer
<activity ...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!-- Include the host attribute if you want your app to respond
only to URLs with your app's domain. -->
<data android:scheme="http" android:host="www.example.com" />
<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>
您需要考虑可能适用的各种情况。
请参考下面的意图过滤器。最后还提供 link 。
<activity android:name="BrowserActivity"
android:label="@string/application_name"
android:launchMode="singleTask"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/BrowserTheme"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- For these schemes were not particular MIME type has been
supplied, we are a good candidate. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<!-- For these schemes where any of these particular MIME types
have been supplied, we are a good candidate. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="inline" />
<data android:mimeType="text/html"/>
<data android:mimeType="text/plain"/>
<data android:mimeType="application/xhtml+xml"/>
<data android:mimeType="application/vnd.wap.xhtml+xml"/>
</intent-filter>
<!-- We are also the main entry point of the browser. -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- The maps app is a much better experience, so it's not
worth having this at all... especially for a demo!
<intent-filter android:label="Map In Browser">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="vnd.android.cursor.item/postal-address" />
</intent-filter>
-->
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
查看您可能需要的不同类型的意图过滤器,以涵盖所有可能的情况。
参考这个link - froyo 浏览器的完整清单文件。
考虑将 CATEGORY_APP_BROWSER
与您的主过滤器一起使用:
Used with
ACTION_MAIN
to launch the browser application. The activity should be able to browse the Internet.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.APP_BROWSER" />
</intent-filter>
您可以通过编程方式实现此目的,如下所示:
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
share.setPackage("your.app.package.name");
startActivity(share);
如果您在 phone 上检查应用程序是否存在,那也很好。
快乐编码:)