【问题标题】:Opening Android application from website not working从网站打开 Android 应用程序不起作用
【发布时间】:2016-05-18 00:21:01
【问题描述】:

我想在我的简单 Android 应用程序中实现这样的功能:当用户在网络浏览器中访问某个链接(比如说 www.example.org)时 - 如果安装了 Android 操作系统,它应该会打开我的 Android 应用程序。

我尝试使用这样的意图过滤器:

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">

        <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.org"
                android:pathPattern="/.*"
                android:scheme="http" />

            <data
                android:host="www.example.org"
                android:pathPattern="/.*"
                android:scheme="http"/>
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

但它在 google chrome 移动浏览器中根本不起作用。在 Firefox 中,当我访问该链接时,我会在搜索栏的右侧看到这样的 Android 图标:

当我按下该图标时 - 我的应用程序打开。但这仍然不是我想要实现的目标。

知道为什么我上面的代码不起作用吗?我尝试了许多我在互联网上找到的意图过滤器声明的变体,但似乎没有任何效果。我有安装了 Android 6 的 nexus 5 设备。

【问题讨论】:

    标签: java android html android-intent web


    【解决方案1】:

    我找到了解决问题的方法。整个互联网上到处都是老例子。

    自 chrome 版本 25 起,谷歌对应用深层链接功能进行了细微更改。更多信息:https://developer.chrome.com/multidevice/android/intents

    所以我的工作代码如下所示:

    Android 端的 Intent 过滤器:

    <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="launcher"
                    android:path="/"
                    android:scheme="test" />
            </intent-filter>
    

    网页html:

    <a href="intent://launcher/#Intent;scheme=test;package=com.example.gediminas.myapplication;end">Launch app</a>
    

    【讨论】:

      【解决方案2】:

      试试这样,去掉路径模式:

      <intent-filter>
          <data android:scheme="http" android:host="twitter.com"/>
          <action android:name="android.intent.action.VIEW" />
      </intent-filter>
      

      更多信息: Launch custom android application from android browser

      【讨论】:

        【解决方案3】:
        <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.org"
                    android:scheme="http" />
        </intent-filter>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-04-01
          • 1970-01-01
          • 2019-04-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-02-08
          相关资源
          最近更新 更多