1

In my TiApp.xml i got the following block :

<activity android:name=".TestActivity" android:label="@string/app_name" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    <intent-filter android:label="@string/kmob.intent.menu.send">
        <data android:mimeType="*/*"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <action android:name="android.intent.action.SEND"/>
    </intent-filter>
</activity>

And it's working great. I can go in the photo gallery, select a photo and i can share the photo with my application. But in my application i got a problem. I need to access to the filename or at least its extension. But i have only a blob with the content of the image.

if (OS_ANDROID) {
    var intent = Ti.Android.currentActivity.getIntent();

    if (intent && intent.action == 'android.intent.action.SEND') {
        // Blob contains the content of the image (an application/octet-stream data). But there's no filename or filepath or file mimetype or whatever
        var blob = intent.getBlobExtra(Ti.Android.EXTRA_STREAM);

        // How can i access the native file or its filename ?
    }
}

How can i access the native file or its filename ? Or at least its extension ? (that's the only thing i need since i have the file content. I can create a temporary file with the content by i need the extension)

In the documentation i can only find examples with simple text files or just displaying the image content. They never access to the native file or its filename.

Here the string representation of intent and blob :

intent = {
    "action": "android.intent.action.SEND",
    "bubbleParent": true,
    "data": null,
    "type": "image/jpeg", // NOTE : This value is not always the same. For an android 4.2.x, it's "image/jpeg", on android 4.1.x, it's "image/*".
    "apiName": "Ti.Android.Intent",
    "flags": 50331649
};

blob = {
    "height": 0,
    "bubbleParent": true,
    "type": 2,
    "mimeType": "application/octet-stream",
    "apiName": "Ti.Blob",
    "nativePath": null,
    "file": null,
    "text": "<IMAGE CONTENT AS STRING>"
}
Magus
  • 14,796
  • 3
  • 36
  • 51

1 Answers1

0

You should try to read the nativePath property of the blob object. This should represent the file location including the name of the file (and the extension I guess).

Another possibility would be to access the blob.file property. Then you can use blob.file.getName() to access the name of the file.

Robin Ellerkmann
  • 2,083
  • 4
  • 29
  • 34
  • Already tried, without success :( The blob only contain the image content. `blob.file` and `blob.nativePath` are both `null`. I will edit my question with the string representation of my blob. – Magus Jul 21 '15 at 06:58
  • It seems that your blob does not represent a file. According to this question: http://stackoverflow.com/questions/13488176/titanium-mobile-photogallery-success-callback-event-property-media-file nativePath and file are cannot be accessed by the dev (at least for iOS, maybe that is also the problem here.) The mimeType = application/octet-stream indicates that the blob does not know which file extension the original file had. – Robin Ellerkmann Jul 21 '15 at 07:34