intent-filter中空主机的说明符是什么?

kka*_*kov 6 android manifest

我正在尝试让我的应用响应这些方案:

我的应用程序内://产品/ XXX

我的应用程序内://

以下代码有效,但我收到警告:android:host不能为空.它仍然有效,但是 - 是否有正确的方法来指定空主机?

我不想将"*"指定为android-host,因为还有其他活动可以处理不同的操作,然后它们不会直接打开,但我会得到一个选择器对话框来选择应该打开的活动.

<activity android:name=".ui.OpenerActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:screenOrientation="portrait" >
        <intent-filter>
            <data android:scheme="my-app" />
            <data android:host="product" />
            <data android:host="" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>
Run Code Online (Sandbox Code Playgroud)

非常感谢!

Max*_*lle 3

URI 中没有主机(或更正式的权限)部分是绝对没问题的。想想常用的file:///tmp/example.file

请注意,无主机的分层 URI 并非不透明(如mailto:john@example.com),而是具有路径。与文件 URI 一样,主机名被单个/.

因此,您的 URI 应采用以下形式my-app:///product/XXX。意图过滤器可能如下所示:

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

  <action android:name="android.intent.action.VIEW"/>

  <data android:host=""/>
  <data android:scheme="my-app"/>
  <data android:pathPrefix="/product"/>
  <data android:pathPattern=".+"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

您仍然会收到有关空主机名的警告,这绝对没问题。此警告是检查Firebase App Indexing的结果,我想这仅在存在网站的情况下才有意义(您可以从中获取主机名,即整个 URI)。

由于您无论如何都不会使用索引,因此您可以通过将以下内容添加到项目中来删除警告lint.xml

<!-- no app indexing without a hostname -->
<issue id="GoogleAppIndexingUrlError" severity="ignore"/>
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请查看URI 规范Wikipedia 上的 file-URIs 条目