【问题标题】:emulated external storage android模拟外部存储android
【发布时间】:2013-01-09 09:31:05
【问题描述】:

我创建具有相机功能的应用程序,我调用相机,意图拍摄照片并将文件保存在外部存储“下载”文件夹中,但随后我搜索它们在另一个文件夹“/storage/emulated/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;

【问题讨论】:

    标签: java android


    【解决方案1】:

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

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

    Context.getExternalFilesDir();
    

    或(API

    Context.getExternalStorageDirectory();
    

    获取当前设备上的外部存储目录(假设已挂载)。

    【讨论】:

    • 我正在使用 getExternalStorageDirectory() 函数,但文件没有出现在映射的内部存储“下载”文件夹中。在设备根(外部存储)“下载”文件夹中的文件是。
    猜你喜欢
    • 2012-04-12
    • 1970-01-01
    • 2013-09-14
    • 2011-03-12
    • 1970-01-01
    • 2012-07-10
    • 2013-03-24
    • 2012-03-30
    • 1970-01-01
    相关资源
    最近更新 更多