简体   繁体   English

如何从网站到Android应用程序的深层链接

[英]How to Deep link from Website to android App

I have a website that is mainly used by mobile users. 我有一个主要供移动用户使用的网站。 I want to link from the website to a separate app, which should then open on the phone (the app is already installed) 我想从网站链接到单独的应用程序,然后应在手机上打开(该应用程序已安装)

For the app, I have entered the following scheme: 对于该应用程序,我输入了以下方案:

 <variable name="URL_SCHEME" value="alfix_smart" />
    <variable name="DEEPLINK_SCHEME" value="https" />
    <variable name="DEEPLINK_HOST" value="domain.com" />
    <variable name="ANDROID_PATH_PREFIX" value="/" />
    <variable name="ANDROID_2_PATH_PREFIX" value="/" />
    <variable name="ANDROID_3_PATH_PREFIX" value="/" />
    <variable name="ANDROID_4_PATH_PREFIX" value="/" />
    <variable name="ANDROID_5_PATH_PREFIX" value="/" />
    <variable name="DEEPLINK_2_SCHEME" value="https" />
    <variable name="DEEPLINK_2_HOST" value="www.domain.com" />

how can I now link a button of a website to the app? 现在如何将网站的按钮链接到应用程序? What do I have to do for that? 我该怎么办? Unfortunately, I have no idea. 不幸的是,我不知道。

I hope you can help me 我希望你能帮帮我

• If you want to handle deep linking in both Android and iOS, it is recommended to use Dynamic Links . •如果要在Android和iOS中处理深层链接,建议使用动态链接 With Dynamic Links , you treat on all platforms such as Android, iOS and web in a similar way. 使用Dynamic Links ,您可以在所有平台(例如Android,iOS和Web)上以类似的方式处理。 It seamlessly transits users from your mobile website to the equivalent content within your app. 它将用户无缝地从您的移动网站转移到应用程序中的等效内容。 To see its usage example, refer to this and this . 要查看其用法示例,请参考thisthis

• If you want to handle deep linking in Android only (and the app is already installed as you mentioned), in simplest approach ( Deep Links ), you can introduce your Activity as a handler of specific pattern URL s and pass the desired parameters as URL query params. •如果您只想在Android中处理深层链接(并且已经按照您提到的方式安装了该应用程序),则可以以最简单的方法( Deep Links )将Activity引入为特定模式URL的处理程序,并将所需的参数传递给URL查询参数。

To see its usage example in details, refer to this . 要详细查看其用法示例,请参考this

In AndroidManifest.xml 在AndroidManifest.xml中

<activity android:name=".YourActivity">

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

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

        <!-- Accepts URIs that begin with "https://example.com" -->
        <data android:host="example.com" />
        <data android:scheme="https" />
    </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" />

        <!-- Accepts URIs that begin with "https://www.example.com" -->
        <data android:host="www.example.com" />
        <data android:scheme="https" />
    </intent-filter>

</activity>

In YourActivity.java: 在YourActivity.java中:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    String action = intent.getAction();
    if(action.equals(Intent.ACTION_VIEW)){
        Uri data = intent.getData();
        if (data.getQueryParameter("some_param") != null && data.getQueryParameter("some_param").isNotEmpty()) {

            String param = data.getQueryParameter("some_param");
            // do what you want to do with param
        }
    }
}

Your html snippet: 您的html代码段:

<a href="https://example.com?some_param=some_value">Click Me!</a>

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

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