Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android get url from browser

Tags:

android

url

I am try to open my app on url click and get value from it, url looks like : path.com/item?key=value

in manifest:

<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="path.com"
        android:pathPrefix="/item"
        android:scheme="http" />
</intent-filter>

but

Uri data = getIntent().getData(); 
data.getPathSegments();
Log.d("TAG", "param is:" + params.get(0);

returns: param is:item /item . how to get key=value or full url

like image 713
Anton Sobolev Avatar asked Mar 15 '23 12:03

Anton Sobolev


1 Answers

This is how I did recently in my app

Use following intent filter

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

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

In your URL use following

for Chrome

window.location = "intent://item?key=value#Intent;scheme=<SCHEME_NAME>;package=<APP_PACKAGE>;";`

other bowsers

window.location = "<SCHEME_NAME>://item?key=value";

In the Activity class use following

String uriPath = getIntent().getDataString();

uriPath will have string "item?key=value" which you can parse based on patterns.

You can Modify the "item?key=value" in your JS to send only value if required. Do experiment on this.

Follow the link for more https://developer.android.com/training/app-indexing/deep-linking.html

like image 116
Abhinav Tyagi Avatar answered Mar 23 '23 14:03

Abhinav Tyagi