I'm trying to save a picture after taking one with PictureCallback. Here is the function :

@Override
public void onPictureTaken(byte[] data, Camera camera)
{
    FileOutputStream imageFileOS = null;

    try {
         imageFileOS = openFileOutput("imageTarget", Context.MODE_PRIVATE);
         imageFileOS.write(data);
         imageFileOS.flush();
         imageFileOS.close();
    }
    catch (FileNotFoundException e) {
         Log.i("Error", "FIle Not Found");
    }
    catch (IOException e) {
         Log.i("erreur", "IOException");
    }
}

But when I connect my phone to my computer, the file size is always 0 byte, and I can't open it.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> is added to my manifest.

Do you have any idea ?

有帮助吗?

解决方案

openFileOutput writes to your internal file system. You will not be able to access this easily from your phone unless it is rooted or you have the app in debug mode and you use the run-as command. The WRITE_EXTERNAL_STORAGE permission doesn't help you in this case.

I suggest checking out this article for more info http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top