在我的 android 应用程序中,我支持在我的应用程序或外部浏览器中打开网站。 所以我将以下代码添加到 android list 中:
<activity
android:name=".MyActivity"
android:screenOrientation="portrait" >
<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>
所以现在当用户试图打开一些 url 时,他会看到一个对话框,他可以在其中选择更喜欢的应用程序来查看这个 url。但我希望我的应用程序仅针对从我的应用程序内部打开的 url 出现在此对话框中。我不希望它出现,例如,当用户试图在 Facebook 应用程序中打开一些外部链接时。有什么方法可以做到这一点吗?
请注意,我的应用支持打开不同的链接,我无法为它们设置任何特定的模式。
最佳答案
But I want my application to appear in this dialog only for urls opened from inside my app.
这是不可能的,抱歉。
您可能可以通过 PackageManager
和 setComponentEnabledSetting()
启用和禁用此组件来伪造此行为,这样它只是当很可能会遇到这样的 URL 时启用。但是,可能很难做到 100% 可靠。
关于android - Intent.category.BROWSABLE : set visibility to external applications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12585660/