简体   繁体   中英

Titanium can't write file in Android Alloy

i have this problem like 2 weeks and i don't know why. I'm using Ti.Paint and i want tos save the draw into a file, so, this is the code:

var paintImage=paintView.toImage().media;
    var tmpImg="paintImage.jpg";;
    var imageFile=Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, tmpImg);
    imageFile.write(paintImage);

And NOTHING happens, nothing at all, the action says "true", but the file does not exist in the Gallery, nor the Cellphone, nor the Android/data/appDirectory, nothing, just nothing. And i don't know why. I use this code to save an image from the camera to the gallery and works flawless:

success:function(event)
    {
        tmpImg="prueba.jpg";
        var imageFile=Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, tmpImg);
        imageFile.write(event.media);
    },

So, can anyone help?, because i have NO idea why this is not working.

Using

Titanium SDK 3.2.2GA with Alloy
Titanium Studio, build: 3.2.3.201404181442
MacbookPro 2012 with OSX Maverick
Device: Motorola XT910

我认为这在Titanium 3.3.0中已修复,并且与mimeType设置不正确的问题有关( https://jira.appcelerator.org/browse/TIMOB-15746 )尝试更新并确保您更改了tiapp.xml中的T​​itanium SDK到3.3.0。

in android, you the better to save the file in the Ti.Filesystem.externalStorageDirectory folder, you can try the below sample code:

var imageFile = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "paintImage.jpg");
if(!imageFile.exists()) {
     imageFile.write(event.media);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM