How to use intent-filer and custom URL scheme in Android

1 minute read

Intent Filter is used to specify the type of intents that the component would like to receive. Custom URL schemes provide a way to refer some resources inside your app. Users tapping a custom URL in the social media such facebook, for example, launch your app in a specified context. Other apps can also trigger your app to launch with specific context data; for example, a photo library app might display a specified image.

Create Deep Links to App Content

Allowing Other Apps to Start Your Activity

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </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="studio" android:host="exitt" />
    </intent-filter>

</activity>

How to call custom URL scheme

1. Web to Android (Already installed)

<a href="studio://exitt?shareid=testid&sharedt=20190920"> Test </a>

studio://exitt?shareid=testid&sharedt=20190920

2. Web to Android (Not installed)

If app is not installed, go to playstore. Otherwise, run your app.

<a href="Intent://exitt?native_pg_id=10&web_pg_id=detail&sns_id=facebook&video_url=https://www.naver.com#$d#Intent;scheme=studio;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=com.invest.stockonair;end"> Test </a>

Intent://exitt?native_pg_id=10&web_pg_id=detail&sns_id=facebook&video_url=https://www.naver.com#$d#Intent;scheme=studio;action=android.intent.action.VIEW;category=android.intent.category.BROWSABLE;package=com.invest.stockonair;end

3. Web to Android (Always go to playstore)

Intent://details#Intent;scheme=market;package=com.starstock.startv;end

4. Android to Android

String url ="test_app_link://test_detail?test_param=10";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);

How to read data from intent parameters

Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
    Uri uri = intent.getData();
    String strid = uri.getQueryParameter("shareid");
    String strdt = uri.getQueryParameter("sharedt");
}

Tags:

Categories:

Updated:

Leave a comment