views:

577

answers:

1

Hi!

I need a good way of sending information TO the Android device that doesn't use a special server that has XML data. I would like to base this around email functionality. Lets say I send an email with some special text/link that when clicked starts and intent on the phone.

I don't want to replace the users current email application. A clickable link would be the best thing "intent://data1:data2" or something along these lines.

Speculations/solutions on how to proceed.

+1  A: 

Yes, you can do that. You register an activity in your app as the handler for your own protocol (scheme). The application manifest will have something like:

    <activity android:name=".SchemeActivity"
        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="myownprotocol" />
        </intent-filter>
    </activity>

This activity will not be displayed or get an icon in the application launcher so you probably have an "ordinary" activity in addition to this one.

Now, any web page can have link like the following:

<a href="myownprotocol://12345">Sample link</a>

With the application installed, you should be able to click such a link in the web browser and have the SchemeActivity in my sample be shown. Inside that activity, you can fetch the whole link (and parse the additional id/data or whatever you have there) by:

String fullUrl = getIntent().getDataString();
mikeplate
Just realized that this thread explains something similar: http://stackoverflow.com/questions/525063/android-respond-to-url-in-intent
mikeplate
Note that whether this works apparently varies by email client and/or email format. Not everything makes clickable links. Test, test, test.
CommonsWare
You won't get away with this in the default gmail app.
alex
True. I missed that mail was an important part of the question. Then I don't think it is possible without the assistance of your own web server to deliver a custom mime type that you register with your activity.
mikeplate