2013-01-09 104 views
0

我创建应用程序的相机功能,我打电话相机与意图抓拍并保存在外部存储“下载”文件夹中的文件,但后来我搜索他们,他们是在另一个文件夹“/ storage/emulated/0 /下载/”。模拟外部存储android

为什么android需要2个导演?使用相同的文件,例如我保存的照片。

我正在使用Galaxy Nexus手机。对于Galaxy平板电脑,一切都很好。

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; 

回答

0

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal,有些设备使用不同的目录作为外部存储。

你应该尝试(API> = 8):

Context.getExternalFilesDir(); 

或(API < 8)

Context.getExternalStorageDirectory(); 

来得到当前的设备上的外部存储目录(假设它被安装) 。

+0

我使用getExternalStorageDirectory()函数,但文件不会出现在映射的内部存储“下载”文件夹中。在设备根目录(外部存储)中有“下载”文件夹文件。 – Justinas