views:

66

answers:

2

Google maps now offers a way to "share a place" with what appears to be a predefined list of sources. When users search for a place on Google Maps, whether it's a specific address, cross-street, or restaurant name, there's a new button called "share this place" that posts the location info to Google Buzz, Facebook, Twitter, or via e-mail or SMS. I would like to either have my application included in this list or determine how to obtain the lat/lon of that selected location. Does anyone have any ideas?

Peace, Scott

+2  A: 

I figured it out. Here's a sample manifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yourapp" android:versionCode="1"
    android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".YourApp" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND"></action>
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
</manifest> 

Simply add the SEND intent filter just as it is above to your activity. The "share this place" simply performs a "SEND" intent with the mime type of "text/plain". If you register an intent filter for that type, then your app will show up in the list. Mine did. =)

HenryAdamsJr
Thanks Henry! I will give this a try as soon as the alligators allow.
stanlick
Sweet, that worked great! Now then, how is it working? Does my app have to be running to show up in the map's "share this place?" I don't see the connection between the two. Also, do I need a broadcast receiver or some such to receive the call back when the user selects my app?
stanlick
The way I've shown you above tells Android that your app can receive a send intent of type "text/plain". Your app does not have to be running for it to be in the list because when you select it, Maps with actually launch the activity your intent filter is defined on. Then, you simply pull the text out of the context that's passed to the activity.
HenryAdamsJr
Is there any documentation concerning what I might expect to get back in the Bundle extras? I have experimented with a few places and what I get back appears to be nearly random! bundle.get("android.intent.extra.TEXT") returns a String where the variable number of lines are separated by a /n char. Also, some of the lines start off with a number (1,2,3) and others do not. I thought the 1 might signify phone number, however, some phone numbers returned were not preceded by the 1! Fishing random data out of a Bundle is crazy!
stanlick
I didn't find any documentation, and I doubt there is any. I just played around with it until I got what I needed. I just wanted to be able to pull out the GPS coordinates. Also, could you please accept my answer. =)
HenryAdamsJr
A: 

THX! I searched too long to get that answer.

Can you tell me how i can figure out what intent filters I need for other applications in order to list my app in menus like the "share place" menu?

how did you find out - brute force?

serprime