Search code examples
androidandroid-intentandroid-filterandroid-implicit-intent

Open my app from a link


In my app the server send this link: appname://[email protected]&token=asdf-asdf-asdf-xcfghfgh but is it possible to get the values like email= [email protected] and the token = sdfdkgdkgjgfd.

So far I've only added this intent filter inside my manifest but the app is not called:

<intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.SEND"/>
                <category android:name="android.intent.category.DEFAULT"/>

                <data android:mimeType="text/plain" android:scheme="appname://"/>
            </intent-filter>

Note this should open my app when the link is clicked in the browser


Solution

  • You can get the email and token by getting the Activity's intent like this:

        <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                        <action android:name="android.intent.action.SEND"/>
                        <category android:name="android.intent.category.DEFAULT"/>
    
                        <data android:mimeType="text/plain" android:scheme="https" 
                         android:host="api.myapp.com"
                         android:pathPrefix="/api/v2/verify"/>
           </intent-filter>
    

    Intent intent = getIntent();
    Uri data = intent.getData();
    String email = data.getQueryParameter("email");
    String token = data.getQueryParameter("token");