我创建带有相机功能的应用程序,我调用相机意图拍摄并将文件保存在外部存储"下载"文件夹中,但随后我搜索它们,它们在另一个文件夹"/storage/emululated/0/download/"中。
为什么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;
从http://developer.android.com/guide/topics/data/data-storage.html#filesExternal,一些设备使用不同的目录作为外部存储
你应该试试(API>= 8):
Context.getExternalFilesDir();
or (API <8)
Context.getExternalStorageDirectory();
获取当前设备上的外部存储目录(假设它已挂载)。