Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.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浏览器中创建我网站的链接启动我的应用程序,但不在链接有特定部分时启动_Java_Android_Url_Web_Intentfilter - Fatal编程技术网

Java 如何在Android浏览器中创建我网站的链接启动我的应用程序,但不在链接有特定部分时启动

Java 如何在Android浏览器中创建我网站的链接启动我的应用程序,但不在链接有特定部分时启动,java,android,url,web,intentfilter,Java,Android,Url,Web,Intentfilter,我将实现这个场景: www.example.com->启动我的应用程序 http://example.com->启动我的应用程序 http://www.example.com->启动我的应用程序 https://example.com->启动我的应用程序 https://www.example.com->启动我的应用程序 但是 http://example.com/dont/start/app->在默认浏览器中打开链接 通过始终使用意图过滤器,它将打开我的应用程序 <activit

我将实现这个场景:

www.example.com->启动我的应用程序

http://example.com->启动我的应用程序

http://www.example.com->启动我的应用程序

https://example.com->启动我的应用程序

https://www.example.com->启动我的应用程序

但是

http://example.com/dont/start/app->在默认浏览器中打开链接

通过始终使用意图过滤器,它将打开我的应用程序

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <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:host="example.com" />
        </intent-filter>
    </activity>

在这种情况下,一种方法是直接打开浏览器。像这样

onCreate() {
  if(uri is in path we don't want) {
    open browser directly via intent
    finish();
    return;
  }
  //Handle a URL we do want
}

要直接打开浏览器,您可以通过确定默认浏览器是什么,并显式启动它。

能否显示java代码?@PranjalCholadhara代码已添加。它无法工作。这是错误:java.lang.NullPointerException:尝试在空对象引用已知错误上调用虚拟方法“boolean android.content.Intent.migrateExtraStreamToClipData()”。当您试图在未安装GooglePlayServices的设备上使用需要GooglePlayServices的东西时,就会发生这种情况。我不知道你在做什么需要它,因为在这个问题上没有讨论需要它。