birdy
birdy

Reputation: 9646

How to receive a URL from my android app after being forwarded from browser.

When a user visits the browser page for my app I am forwarding them to a url scheme like so:

intent://share?id=123#Intent;package=com.aerstone.mobile;scheme=myapp;launchFlags=268435456;end;

I've tested this and this works fine. Now, when the user visits my app's home page from the browser and have the app installed, the app automatically opens up.

Relevant part from my manifest is:

    <activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name"
        android:name=".ui.activity.MainActivity"
        android:launchMode="singleTask" >
        <!-- add the above launchMode attribute -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <!-- add the below additional 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"/>
            <data android:scheme="myapp"/>
        </intent-filter>
    </activity>

Question

After the app opens up, how can I fetch the URL? I want to fetch the id=123 part of the URL. How can I do this?

Upvotes: 0

Views: 1033

Answers (2)

Shivam Verma
Shivam Verma

Reputation: 8023

In onCreate()

Uri uri = getIntent().getData(); //Returns the URI that was used. 
String id = uri.getQueryParameter("id"); //Gives any parameter passed in the URI. 

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007359

Call getIntent().getData() in onCreate(), or getData() on the passed-in Intent to onNewIntent(), depending on whether your activity was already created or not. That will return the Uri representing your URL.

Upvotes: 1

Related Questions