简体   繁体   English

当重定向到 Android 应用程序时,我们如何从 URL 中提取值?

[英]How can we extract values from URL when redirect to a Android app?

Currently, I am using this link目前,我正在使用这个链接

https://developer.android.com/studio/write/app-link-indexing#java

To understand the support links in an Android app.了解 Android 应用程序中的支持链接。 Now if the supported link in like this现在,如果支持的链接像这样

https://app.example.com?refer=A91NB

or或者

https://app.example.com/A91NB

How can we extract the refer value from the URL when it's redirected to the app.当它被重定向到应用程序时,我们如何从 URL 中提取引用值。

Uri uri = getIntent().getData();

    if (uri != null) {
        List<String> params = uri.getPathSegments();
        String id = params.get(params.size() - 1);
        Toast.makeText(MainActivity.this, "ID :" + id, Toast.LENGTH_LONG).show();
    }

Write this code in the activity into which your link is being redirected to.在您的链接被重定向到的活动中编写此代码。

The ".get(params.size() - 1" will fetch the data for the last segment. “.get(params.size() - 1”将获取最后一段的数据。

For eg.例如。 https://app.example.com/A91NB : It will give you => https://app.example.com/A91NB :它会给你=>

A91NB A91NB

You can modify the above code according to the placement of the required data in the link.您可以根据链接中所需数据的位置修改上述代码。

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

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