0

我使用以下代码获取存储在 SD 卡文件夹中的照片。这工作正常。但照片也存储在 SD 卡图像文件夹中,并显示在 androids 照片库中。为什么?

提前致谢!

public class Foto extends Activity implements SurfaceHolder.Callback,
    OnClickListener {

private static final int CAMERA_ACTIVITY = 1;
private static final int TAKE_PICTURE = 1;
File archive, root, folder;
String fec;

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    String storageState = Environment.getExternalStorageState();
    if (storageState.equals(Environment.MEDIA_MOUNTED)) {

        String path = Environment.getExternalStorageDirectory().getName()
                + File.separatorChar + "TEST" + "/"
                + "test.jpg";
        archive = new File(path);
        try {
            if (archive.exists() == false) {
                archive.getParentFile().mkdirs();
                archive.createNewFile();
            }
            if (archive.exists() == true) {

                archive.createNewFile();
            }

        } catch (IOException e) {
            Log.e(ACTIVITY_SERVICE, "Could not create file.", e);
        }
        Log.i(ACTIVITY_SERVICE, path);

        Uri _fileUri = Uri.fromFile(archive);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, _fileUri);
        startActivityForResult(intent, TAKE_PICTURE);


        setResult(RESULT_OK, intent);
        finish();
    } else {
        new AlertDialog.Builder(Foto.this)
                .setMessage(
                        "External Storeage (SD Card) is required.\n\nCurrent state: "
                                + storageState).setCancelable(true)
                .create().show();

        finish();
    }

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();

}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

}

@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

}

4

1 回答 1

1

在大多数设备上,MediaStore.ACTION_IMAGE_CAPTURE 除了它所做的任何其他事情外,还会保存到画廊,即使您不要求返回文件,只是一个 URI。我知道在 Nexus 7 上它并没有这样做,但是,这真的很糟糕,行为是如何神奇地不同并且很烦人。无论如何,还要注意,如果媒体扫描仪已经赶上,Gallery 实际上会在 SD 卡上的任何位置显示没有 .nomedia 文件的任何内容。

于 2012-09-17T02:36:34.147 回答