3

I've created an app that can upload images from my phone (Samsung Galaxy S2) to my server, using "Share via"...<my app> when viewing the image in the Android Gallery.

However, my app does not show up as an alternative in the "share via"-menu for images that I have online, in Picasa. I'm wondering how to be able to handle all sorts of images that show up in the gallery - both locally stored on the phone/sd card and stored remotely in eg Picasa?

Now I have intent-filters on mime type "image/*", I suppose this does not match the Picasa images, for some reason(?).

From my AndroidManifest.xml:

    <activity
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name=".PublishImageActivity"
        android:theme="@style/Theme.Custom" >
        <intent-filter >
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>
    </activity>
    <activity
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:name=".PublishImageActivity"
        android:theme="@style/Theme.Custom" >
        <intent-filter >
            <action android:name="android.intent.action.CHOOSER" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>
    </activity>
boffman
  • 433
  • 1
  • 5
  • 13

1 Answers1

2

After some struggling, and using the excellent app "Intent Intercept", I found that the picasa images have mime type "text/plain", and they have an URL string in Intent.EXTRA_TEXT.

So what I did to get around this, was to add intent filters like above, but for "text/plain" in the Manifest;

       <intent-filter >
            <action android:name="android.intent.action.SEND" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="text/plain" />
        </intent-filter>

..And in the Activity, check if a value for Intent.EXTRA_TEXT is bundled in the Intent - if so, get it and check if it's a http link.. And if so - download the image from the URL;

    if (Intent.ACTION_SEND.equals(intent.getAction())) {
        Bundle extras = intent.getExtras();
        if (extras.containsKey(Intent.EXTRA_TEXT)) {
            Uri uri = Uri.parse((String) extras.getCharSequence(Intent.EXTRA_TEXT));
            if (uri != null) {
                String scheme = uri.getScheme();
                if (scheme.equals("http")) {
                    downloadImage(uri);
                    // ...

However I'm still curious if there is a better way to handle this? Feels like I don't have any guarantees now, that the URL really points to an image or some other naughty stuff :-)

boffman
  • 433
  • 1
  • 5
  • 13