简体   繁体   中英

Open Image Gallery Android

I made a camera application and save images in DCIM/Yogyakarta, but I can't open that directory. It can only be opened at DCIM/.

Can anyone tell my why I can't open the directory, and how I can fix it?

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);
         }
    });

Just replace your getAlbumStorageDir method with below@

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

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

It require "/" to fetch correct path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM