0

I'm working with Titanium SDK 2.1.3 and developing for both iOS and Android. Our application can open files (at the moment txt and images on Android), in iOS we use a special library that handles the files while in Android we want to open the files using Android's intents. But this causes an exception with images on Android, saying got exception decoding bitmap. Here's my code that makes the Intent:

var appFile = Ti.Filesystem.getFile(fileNativePath);
if(appFile)
{                           
    var intent = Ti.Android.createIntent({
        action : Ti.Android.ACTION_VIEW,
        type : appFile.read().mimeType,
        data : appFile.nativePath
    }); 
    try {
        Ti.Android.currentActivity.startActivity(intent);
    }
    catch(e)
    {
        Ti.API.error(e);
        alert('No apps for this');
    }
}

The native path for the image I'm trying to open is the following:

file:///data/data/nenvo.com.desktop/app_appdata/1372368987874.jpg

The full Exception is the following:

[ERROR][UriImage( 2887)] got exception decoding bitmap 
[ERROR][UriImage( 2887)] java.lang.NullPointerException
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeInputStream(Util.java:336)
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeBitmap(Util.java:307)
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeBitmap(Util.java:299)
[ERROR][UriImage( 2887)]    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94)
[ERROR][UriImage( 2887)]    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:86)
[ERROR][UriImage( 2887)]    at com.android.camera.gallery.UriImage.thumbBitmap(UriImage.java:120)
[ERROR][UriImage( 2887)]    at com.android.camera.ImageGetter$ImageGetterRunnable.executeRequest(ImageGetter.java:173)
[ERROR][UriImage( 2887)]    at com.android.camera.ImageGetter$ImageGetterRunnable.run(ImageGetter.java:149)
[ERROR][UriImage( 2887)]    at java.lang.Thread.run(Thread.java:856)
[WARN][NetworkManagementSocketTagger(   76)] setKernelCountSet(10044, 0) failed with errno -2
[ERROR][UriImage( 2887)] got exception decoding bitmap 
[ERROR][UriImage( 2887)] java.lang.NullPointerException
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeInputStream(Util.java:336)
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeBitmap(Util.java:307)
[ERROR][UriImage( 2887)]    at com.android.camera.Util.makeBitmap(Util.java:299)
[ERROR][UriImage( 2887)]    at com.android.camera.gallery.UriImage.fullSizeBitmap(UriImage.java:94)
[ERROR][UriImage( 2887)]    at com.android.camera.ImageGetter$ImageGetterRunnable.executeRequest(ImageGetter.java:204)
[ERROR][UriImage( 2887)]    at com.android.camera.ImageGetter$ImageGetterRunnable.run(ImageGetter.java:149)
[ERROR][UriImage( 2887)]    at java.lang.Thread.run(Thread.java:856)

What's wrong with my approach? Thanks for any help in advance.

Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97

1 Answers1

0

The path looks like it is read-only as it is in the apps data directory, so you cant share it through an intent...

So looks like you have a few options, either copy it somewhere else, or just share the whole image itself as a blob.

This happens because (from what I can tell) the underlying Viewer native to the Android platform throws and exception when the permissions are READ_ONLY. This answer has a little more information about that.

Community
  • 1
  • 1
Josiah Hester
  • 6,065
  • 1
  • 24
  • 37