Drawing Application how to save drawing in android phone memory - android

I try to save in png file format. It dose't work when i try to publish to android phone. i do not understand how android phone path from folder to folder work. how do i make it work...
I try the same Actionscript 3 and publish it on my pc and it work....
pls help. sorry bad grammar.
function export():void
{
var bmd:BitmapData = new BitmapData(480, 800);
bmd.draw(board);
var ba:ByteArray = PNGEncoder.encode(bmd);
var file:FileReference = new FileReference();
file.save(ba, "MyDrawing.png");
}

This is the way i save images on Android:
var file:File = File.applicationStorageDirectory.resolvePath("MyDrawing.png");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeBytes(ba, 0, ba.length);
stream.close();

why you wants to save your drawing in phone memory ?How can u tackle when memory size exceeds ?
Anyway Refer this Link,
http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Related

Unable to find saved image

I'm very new to Android. I'm working with Xamarin and I have to take a picture with camera and save the picture.
I achieved to take the picture, I have a Bitmap object. Then I save it without error but when I try to find it, there is no file.
There is my code :
Bitmap imgBmp = /* image initialized */
//Save image on folder
var folderPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var filePath = System.IO.Path.Combine(folderPath, "image1.png");
var stream = new System.IO.FileStream(filePath, FileMode.Create);
bool isOK = imgBmp.Compress(Bitmap.CompressFormat.Jpeg, 95, stream);
stream.Flush();
stream.Close();
I have no error when execute, isOK is true but when I search for the image.png I'm unable to find the file.
With debugger I saw that the path is : /data/user/0/com.myCompagny.MyAppli/files/image1.png but I can not see that folder.
Can someone help me to find my image1.png ?
Or to change the default folder to something like Pictures\MyApplication\image.png but I don't know how to find default folder for images.
Your file is there, but you have no permissions to see it. App directories are only readable to the owning app's uid. If you try to find your file through the shell, your uid is different.
You should try to use another folder path if you want to save file in a world readable location.
I'm just guessing but maybe System.Environment.SpecialFolder.CommonPictures would do.

AS3 for Android, Saving a file in the external storage (Only visible when phone restarts)

I´m having trouble finding my file in the device
I am saving a file in the external storage, specifically using this code
private function saveFiles():void
{
var file1:File = File.applicationStorageDirectory.resolvePath("v/appstorage.doc")
var file2:File = File.cacheDirectory.resolvePath("v/cache.doc")
var file3:File = File.desktopDirectory.resolvePath("v/desktop.doc")
var file4:File = File.documentsDirectory.resolvePath("v/documents.doc")
var file5:File = File.userDirectory.resolvePath("v/userdir.doc")
saveFile(file1)
saveFile(file2)
saveFile(file3)
saveFile(file4)
saveFile(file5)
}
private function saveFile(file:File):void
{
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes(body);
stream.close();
}
No file is visible after this when you connect your phone again, I tried killing the app, I tried reconnecting the USB cable, hitting F5 to update the folder.
The files are only visible when I restart my phone, so, my question is:
What can I do to save the file and make it visible when I save the file without restarting my phone?
The file is saved in the folder v you can access those by connecting your phone via USB after the restart, I can see desktop.doc, documents.doc and userdir.doc, the variable body is the string "Hello world" ,
the phones I am using is a Moto G with Lollipop, and an HTC One S with Jelly Bean
And I am using
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
If someone could please help me with this issue, that would be great!
For picture you need to use mediaScanIntent Android Doc
After some quick research here could be a solution solution for files
This was the answer... https://android.stackexchange.com/questions/53422/folder-on-phone-not-showing-in-windows
It did happen to me in native language as well, it seems it is related to the MTP cache

FLEX MOBILE: Can't read images "saved" on local filesystem on my android tablet

I'm downloading some images into my application so they can be displayed without consuming any bandwidth. The code I'm using to store the images on my android device is the following:
var file:File = File.applicationDirectory.resolvePath(fileName);
if (file.exists)
{
file.deleteFile(); //delete it if exists
}
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(data, 0, data.length);
fileStream.close();
var showLocalPath:String = file.nativePath;
To display the images I'm using the following two examples:
<s:BitmapImage id="iconStateImage" source="{appContext.CurrentState.IconImage}"/>
<s:Image id="backgroundStateImage" left="0" right="0" top="0" bottom="0" source="{File.applicationDirectory.resolvePath(appContext.CurrentState.BackgroundImage)}"/>
Both appContext.CurrentState.IconImage and appContext.CurrentState.BackgroundImage have the same path of the former fileName. Even though I'm trying to load the images with full path (second case) or with a short path (first one), I'm not able to display it.
I already set the WRITTING permissions on the project.
Can some help me with this? Thanks in advance.
Regards,
Sebastián
File.applicationDirectory is read-only; you'll want to use File.applicationStorageDirectory instead.
See also How can you delete a file in the application directory? and the Flex File documentation.
Then add "app-storage:/" before the image path:
<s:Image id="backgroundStateImage" source="app-storage:/{appContext.CurrentState.BackgroundImage}"/>

write file in adobe air for android

hello evrey body i have try really hard to write a file to android and so far no secceus.
this is the code i am using.
function writeAirFile():void
{
// Change the folder path to whatever you want plus name your mp3
// If the folder or folders does not exist it will create it.
var file:File = new File("/mnt/sdcard/new/new.apk");
//file.nativePath = "/mnt/sdcard/new/new.apk";
trace(file.nativePath);
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The file is written.");
trace(file.nativePath);
}
uts need to work but it is not.
i already add th permission for local storge writing
please i need help
thanks a lot for all of you for helping!
Point out custom directory is not best practices better you can use File.applicationStorageDirectory so no need worry about security and permission related issue.
var file:File = File.applicationStorageDirectory.resolvePath("new/new.apk");
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The file is written.");
trace(file.nativePath); // you can find where it is stored.
Suggestion always use Async mode file operation so that UI freeze won't happen even if file size is too large.

Adobe Flex AIR download videos in Android device

I want to download a set of video files to a default folder path in an Android device and then have access to the path and files. The FileReference class does not support this features. Is there another way? Thank you.
I dont use file reference at all. I use a Loader to download the file. I then create a new File object with the path where I want to save the file, and use a FileSteam to write the data from the loader to the file.
var req:URLRequest = new URLRequest(url);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handler);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);
function handler(e:Event):void{
var file:File = new File(path);
var stream:FileSteam();
steam.open(file, FileMode.WRITE);
steam.writeBytes(loader.data);
steam.close();
}
something like this should accomplish what you are looking for. I wrote this code from memory so it may not be exactly correct but should be good enough to get you going. Make sure you put this in a try/catch since file and filesteam both throw exceptions

Categories

Resources