简体   繁体   中英

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. 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.

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.

For eg. https://app.example.com/A91NB : It will give you =>

A91NB

You can modify the above code according to the placement of the required data in the link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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