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.

4

1 回答 1

0

该路径看起来像是只读的,因为它位于应用程序数据目录中,因此您无法通过意图共享它......

所以看起来你有几个选择,要么将它复制到其他地方,要么只是将整个图像本身作为一个 blob 共享。

发生这种情况是因为(据我所知)Android 平台原生的底层查看器在权限为 READ_ONLY 时抛出异常。这个答案有更多关于这个的信息。

于 2013-07-01T18:57:41.943 回答