简体   繁体   中英

emulated external storage android

I creating apps with camera function, I call camera with intent snap the shot and saving files in external storage "download" folder, but then I search them they are in another folder "/storage/emulated/0/download/".

Why android needs 2 directors? With same files excep my saved photos.

I'm using Galaxy Nexus phone. For Galaxy tablet everything is allright.

public void openCamera(View view) {
    try {
        int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 1991;

        photoName();
        String _path = Environment.getExternalStoragePublicDirectory(DOWNLOAD_SERVICE) + "/" + photoFileName;
        System.out.println("PATH: "+ _path);
        File file = new File( _path );
        Uri outputFileUri = Uri.fromFile( file );

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);

    } catch (Exception e) {

    }



private String photoName() {
   boolean isWhile = true;
   int randomId = 0;
   int count = 0;

   while (isWhile) {
       photoFileName = "MobiliSkaita_" + count + ".jpg";
       File fileToCheck = new File(Environment.getExternalStoragePublicDirectory(DOWNLOAD_SERVICE) + "/" + photoFileName);

       if (fileToCheck.exists()) {
           System.out.println("FAILAS YRA: " + randomId);
           randomId++;
           photoFileName="MobiliSkaita_" + randomId + ".jpg";
       } else {
           System.out.println("FAILAS NERA: " + randomId);
           isWhile = false;
       }
       count++;
   }    
   return photoFileName;

From http://developer.android.com/guide/topics/data/data-storage.html#filesExternal , some devices use different directories for external storage.

You should try (API >= 8):

Context.getExternalFilesDir();

or (API < 8)

Context.getExternalStorageDirectory();

to get the external storage directory on the current device (assuming it is mounted).

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