0

Im using a Camera intent to create a picture file in internal storage on android. This picture is saved in the app directory as

/data/data/com.company.app/files/test.png

This works fine, the picture is there.

When I with CCFileUtils then tries to check if the file exists (using js interface):

cc.FileUtils.getInstance().isFileExist("/data/data/com.company.app/files/test.png")

it returns false. Opening the file with CCSprite is totally hopeless too.

The owner and group of the app is the same as the app itself(i.e. "com.company.app"). The read/write permissions of my file is rw-rw-r.

EDIT: Adding information to add information.

The device from which I've extracted the information is a rooted Samsung Galaxy S running Cyanogenmod 11(exact build number: 11-2014112-SNAPSHOT-M12-galaxysmtd) which is built on top of android version 4.4.4.

Its internal storage so its the device own storage. That means it can't be on a sdcard if Im correct, im not sure, but its not removable media anyhow and its not in a sdcard folder on the device.

I've also tried to do the same on a 1+ one running CM11(exact build number: 11.0-XNPH44S). This device is not rooted so I can't check it's filesystem. But it seems to handle it the same way.

  • Is the file on an SD card? What Android version? I remember something about how a recent Android OS update severely restricted access to SD cards. – CodeSmile Feb 06 '15 at 12:00
  • "Im using a Camera intent to create a picture file in internal storage on android" -- since third-party camera apps cannot write to your portion of internal storage, I rather doubt that this is what you are doing. Also, I have never seen a camera app write a PNG file (they usually use JPEG). Finally, **do not hardcode paths**, as your hardcoded path will be wrong on Android 4.2+ tablets and Android 5.0+ phones for secondary accounts. – CommonsWare Feb 06 '15 at 12:26
  • I'll walk back the first part of my answer -- there may be ways with a `ContentProvider` that you could get a camera app to write to your app's internal storage without major security issues. But I would recommend that you pull down the file and examine it. My guess is that it is actually a JPEG file, as the camera app probably ignored your file extension. If `CCSprite` either expects the file to be a PNG or be accurately named, I can see where `CCSprite` would fail. – CommonsWare Feb 06 '15 at 12:36
  • "Its internal storage so its the device own storage" -- you may also wish to learn the difference, in Android SDK terms, between [internal storage](http://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html), [external storage](http://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html), and [removable storage](http://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html). The paths you cite are for internal storage, and the paths vary by the Android user account running your app, so don't hardcode them, use `getFilesDir()` instead. – CommonsWare Feb 06 '15 at 12:38
  • You actuallly can let other apps write to your internal storage if you open the file with correct read/write permissions, ;) : http://stackoverflow.com/questions/7720383/camera-intent-not-saving-photo Ill keep that in mind that some cameras dont save in PNG, my camera app can do it though, I can see the image, I know it contains an image as I've opened it and checked it. – Jonathan Lundholm Feb 06 '15 at 12:44

0 Answers0