打开Android图像库

时间:2013-02-18 10:30:00

标签: java android android-gallery

我制作了相机应用程序并在DCIM / Yogyakarta中保存图像,但我无法打开该目录。它只能在DCIM /打开。

任何人都可以告诉我为什么我无法打开目录,以及如何解决它?

public final class FroyoAlbumDirFactory extends AlbumStorageDirFactory {

@Override
public File getAlbumStorageDir(String albumName) {
    // TODO Auto-generated method stub
    return new File(
      Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_DCIM
      ), 
      albumName
    );
 }
}


@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mAlbumStorageDirFactory = new FroyoAlbumDirFactory();


    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);

    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
        storageDir = mAlbumStorageDirFactory.getAlbumStorageDir("Yogyakarta");              

            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(storageDir),"*/*");

            startActivityForResult(intent, RESULT_LOAD_IMAGE);
         }
    });

1 个答案:

答案 0 :(得分:1)

只需将您的getAlbumStorageDir方法替换为以下@

即可
public File getAlbumStorageDir(String albumName) {
        // TODO Auto-generated method stub

        return new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),"/"+ albumName);
     }

需要“/”才能获取正确的路径。