Open my application from the link

In my application, the server sends this link: appname://veryfy?email=test@mail.com&token=asdf-asdf-asdf-xcfghfghbut is it possible to get values ​​of type email= test@mail.comand token = sdfdkgdkgjgfd.

So far I have added this intent filter to my manifest, but the application is not being 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 application when the link is clicked in the browser.

-1
source share
4 answers

You can receive email and token by receiving the intention of the Action as follows:

    <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");
+2
source

Your filter scheme should just be appname, not appname: //

android:scheme="appname"
0
source

:

<intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="text/plain" android:scheme="appname"/>
</intent-filter>

:

<a href="appname://veryfy?email=test@mail.com&token=asdf-asdf-asdf-xcfghfgh">

Getting data in your business:

// check if this intent is started via custom scheme link
Intent intent = getIntent();
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_VIEW) {
   Uri uri = intent.getData();
   String scheme = uri.getScheme();
   if (scheme.equals("appname") {
      String email = uri.getQueryParameter("email");
      String token = uri.getQueryParameter("token");
   }
}
0
source

try it

    <activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" 
          android:exported="true">
        <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>
</activity>

To get your url parameter, write this in your activity.

Uri data = getIntent().getData();
String scheme = data.getScheme(); 
String host = data.getHost(); 
List<String> params = data.getPathSegments();
String first = params.get(0); 
String second = params.get(1); 
0
source

Source: https://habr.com/ru/post/1619799/


All Articles