Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android,通过我的应用程序打开url_Java_Android - Fatal编程技术网

Java Android,通过我的应用程序打开url

Java Android,通过我的应用程序打开url,java,android,Java,Android,我有我的自定义网站,我的android应用程序将在那里获取数据 我们把它叫做example.com 我的android应用程序可以通过WhatsApp等其他应用程序共享链接。当链接被共享时,它会创建类似http://example.com/my/path/to/information 单击此链接时,我想打开自己的应用程序。在我的AndroidManifest文件中,我添加了以下几行代码: <intent-filter> <action android:name="and

我有我的自定义网站,我的android应用程序将在那里获取数据

我们把它叫做
example.com

我的android应用程序可以通过WhatsApp等其他应用程序共享链接。当链接被共享时,它会创建类似
http://example.com/my/path/to/information

单击此链接时,我想打开自己的应用程序。在我的
AndroidManifest
文件中,我添加了以下几行代码:

<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:host="example.com" android:pathPattern="/.*" android:scheme="http"/>
</intent-filter>
当我使用共享链接的其他应用程序并单击它时,它必须向我建议可以打开此链接的应用程序

但是,它并不建议我的应用程序共享此链接

我错过了什么?我需要在我的android网页中添加
meta
标签吗

==============================================================================================

我发现了一个有趣的结果。在my intent filter中,如果我在另一个流行的网站上编写,该网站有自己的android应用程序,当我点击链接时,它建议打开我的应用程序和自己的应用程序


这是否意味着我需要在我的网页中写些东西?

尝试提供特定的路径前缀。 例如,如果您希望打开
http://example.com/my/path/to/information
那么意图过滤器应该如下所示

<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:host="example.com" android:pathPattern="/my/" android:scheme="http"/>


然后,如果希望使用不同的路径前缀打开同一活动,则需要为每个前缀添加一个数据标记。

我已使用这些方法解决了我的问题

在我的网页中,我已将
链接
标记添加到
标题

<link rel="alternate" href="android-app://com.example.app/example.com/my/path/to/information"/>

在我的清单中,我添加了以下内容:

<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:host="example.com" android:pathPattern="/.*" android:scheme="http"/>
   <data android:host="example.com" android:pathPattern="/.*" android:scheme="https"/>
   <data android:host="example.com" android:pathPattern="/.*" android:scheme="android-app"/>
   <data android:scheme="http"/>
</intent-filter>


这起作用了。现在,当我单击链接时,它会建议我的应用程序打开它。

检查此链接您是否提到任何应该处理您的意图过滤器的活动?是的。此意图筛选器位于处理活动内部。问题是当我在其他应用程序中单击链接时。它建议使用我的浏览器打开,但不建议使用我的应用程序。请将代码添加到建议打开链接的位置。是否在未提供路径的情况下进行了尝试。我的手机不建议我的应用程序打开此链接。
<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:host="example.com" android:pathPattern="/.*" android:scheme="http"/>
   <data android:host="example.com" android:pathPattern="/.*" android:scheme="https"/>
   <data android:host="example.com" android:pathPattern="/.*" android:scheme="android-app"/>
   <data android:scheme="http"/>
</intent-filter>