1

我在三星 Galaxy Nexus 上使用 Android 4.03。日志显示该文件已写入手机内存,但是当我签入 Windows 资源管理器或使用手机图库时,我看不到我刚刚拍摄的照片。

这是我的代码。

    PictureCallback jpegCallback = new PictureCallback() {
    public void onPictureTaken(byte[] data, Camera camera) { 
        FileOutputStream outStream = null;
        boolean mExternalStorageAvailable = false;
        boolean mExternalStorageWriteable = false;
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            mExternalStorageAvailable = mExternalStorageWriteable = true;
            Log.d(TAG, "Can Write ");
            try {

                outStream = new FileOutputStream(String.format("/sdcard/myfile.jpg", System.currentTimeMillis()));  

                outStream.write(data);
                outStream.close();



                Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
            }

        } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
            // We can only read the media
            mExternalStorageAvailable = true;
            mExternalStorageWriteable = false;
            Log.d(TAG, "Cant Write ");
        } else {
            // Something else is wrong. It may be one of many other states, but all we need
            //  to know is we can neither read nor write
            mExternalStorageAvailable = mExternalStorageWriteable = false;
            Log.d(TAG, "Other Error ");
        }
            }
};
4

1 回答 1

6

尝试使用

Environment.getExternalStorageDirectory()

而不是 "/sdcard" 。

于 2012-05-29T09:14:45.400 回答