Search code examples
androidintentfilter

android: How to read intent uri extra data


I need (if it is possible) to handle an "url" like this (in an email I need to open my app ("wics")):

http://wics/resetPassword/[email protected]/FOOBARTOKEN

I have this in my AndroidManifest.xml

<activity android:name=".ResetPasswordActivity">
            android:label="@string/app_name">
            <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="http"
                    android:host="wics"/>
            </intent-filter>   
</activity>

How can I get "[email protected]" and "FOOBARTOKEN" in my ResetPasswordActivity ?

I have insert this code:

Intent intent = getIntent();
Uri uri = (Uri)intent.getData();

But now ? split "uri" string and get 3td and 4th elements ?


Solution

  • Well you could do something like this.

    <meta-data android:name="my_url" android:value="http://wics/resetPassword/[email protected]/FOOBARTOKEN" />
    

    then get it in code.

    ApplicationInfo appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
    Bundle bundle = appInfo.metaData;
    
    String url = bundle.getString("my_url");
    Uri uri = Uri.parse(url);
    

    Then split on the "/" delimiter.

    String[] arr =  url.split("/");
    

    then all you need to do is loop over the arr and find your words. make any sense?