-1

In my app the server send this link: appname://veryfy?email=test@mail.com&token=asdf-asdf-asdf-xcfghfgh but is it possible to get the values like email= test@mail.com 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

Darko Petkovski
  • 3,892
  • 13
  • 53
  • 117

4 Answers4

3

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");
Eric B.
  • 4,622
  • 2
  • 18
  • 33
0

The scheme in your filter should just be appname, not appname://

android:scheme="appname"
drew
  • 2,371
  • 2
  • 19
  • 27
0

Try this:

<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>

and the link on the web:

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

Getting data in your Activity:

// 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");
   }
}
Ander Acosta
  • 1,060
  • 1
  • 12
  • 25
  • and do you have any idea how can i get the email and the token? – Darko Petkovski Sep 24 '15 at 13:08
  • Actually i've just noticed that this is not the link that im getting, can I parse this one: https://api.myapp.com/api/v2/verify?email=test@gmail.com&token=1231-0444-44e0-b‌​b69-4192fd0fec6b – Darko Petkovski Sep 24 '15 at 13:19
  • Ok, then change your scheme with "https". For that there is no conflict if you want to use that scheme to other things, you can verify that the host is the of the web. `if(uri.getHost() .equals("api.myapp.com") ...` – Ander Acosta Sep 24 '15 at 13:24
0

try this

    <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); 
Kishan Vaghela
  • 7,678
  • 5
  • 42
  • 67
  • Actually i've just noticed that this is not the link that im getting, can I parse this one: `https://api.myapp.com/api/v2/verify?email=test@gmail.com&token=1231-0444-44e0-bb69-4192fd0fec6b` – Darko Petkovski Sep 24 '15 at 13:14