简体   繁体   English

Android深层链接

[英]Android Deep linking

I am trying to add deep linking on Android , so in my web page i replace an iframe like this 我正在尝试在Android上添加深层链接,因此在我的网页中我替换了这样的iframe

<iframe  scrolling="no" width="1" height="1" style="display: none;" 
src="myscheme://post/5002"></iframe>

and in my manifest.xml (android app) 并在我的manifest.xml(Android应用程序)

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MyActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

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

            <data android:scheme="myscheme" />
        </intent-filter>
    </activity>
</application>

but when i open the webpage in chrome it didn't show the "open with" dialog to choose my app 但是当我用chrome打开网页时,它没有显示“打开方式”对话框来选择我的应用程序

i tested the deeplinking for android using this and the dialog appears 我使用此测试了android的深层链接,然后出现对话框

adb shell am start -W -a android.intent.action.VIEW  -d "myscheme://whatever" 

The functionality has changed slightly in Chrome for Android, versions 25 and later. Chrome for Android版本25及更高版本的功能略有改变。 It is no longer possible to launch an Android app by setting an iframe's src attribute. 通过设置iframe的src属性,无法再启动Android应用。 you should use the “intent:” syntax instead 你应该使用“intent:”语法

intent://host/#Intent;scheme=protocol;package=com.domain.apppackage;end 意图://主机/#意图;方案=协议;包= com.domain.apppackage;端

The basic syntax for an intent-based URI is as follows: 基于intent的URI的基本语法如下:

intent: HOST/URI-path // Optional host intent:HOST / URI-path //可选主机
#Intent; #意图;
package=[string]; 包= [字符串];
action=[string]; 行动= [字符串];
category=[string]; 类别= [字符串];
component=[string]; 成分= [字符串];
scheme=[string]; 方案= [字符串];
end; 结束;

please check this page 请查看此页面

The iframe solution is not valid anymore with the latest versions of Chrome. 使用最新版本的Chrome,iframe解决方案无效。 As Anas said you need to create a link with an "intent://..:" address. 正如Anas所说,你需要创建一个带有“intent:// ..:”地址的链接。 Also the user needs to do some action to open the link. 用户还需要执行一些操作来打开链接。

To solve this problem I've created a link shortener tool. 为了解决这个问题,我创建了一个链接缩短工具。 You can use it here: http://www.uppurl.com/ 你可以在这里使用它: http//www.uppurl.com/

This tool takes care of creating the appropriate deep links based on the user browser. 此工具负责根据用户浏览器创建适当的深层链接。 I recommend you to use it as it solve a lot of work for you and you don't even need to modify or have a server. 我建议你使用它,因为它为你解决了很多工作,你甚至不需要修改或拥有服务器。

Not sure but you can try to use JavaScript instead of iframe: 不确定,但您可以尝试使用JavaScript而不是iframe:

location.href = "myscheme://post/5002"

Also, just to test whether it's working or not at all, you can try to set host and path on your data element in intent-filter: 另外,只是为了测试它是否正常工作,您可以尝试在intent-filter中设置数据元素的主机和路径:

<data android:scheme="myscheme"
                  android:host="post"
                  android:pathPrefix="502">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM