2017-06-11 124 views
0

我刚开始开发一个android应用程序,所以我需要你的帮助。为什么getExternalFilesDir将我的文件保存到内部存储

这是我的代码。

private File createImageFile() throws IOException{ 
     File image = null; 
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); //Get Date 
     String imageFileName = "JPEG_" + timeStamp + "_"; 
     File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); //Get the directory of pictures 


     if (isExertnalStorageWritable()){ 
      if(isExternalStorageReadable()) { 
       image = File.createTempFile(imageFileName, ".jpg", storageDir); //Create the temp file 
       mCurrentPhotoPath = image.getAbsolutePath(); 
      } 
     } 

     return image; 
    } 

但我的临时文件总是在内部存储器中创建,而不是在外部存储器中创建。

+1

尝试使用Environment.getExternalStorageDirectory()获取设备的基础文件夹,而不是应用程序特定的文件夹 – pantos27

回答

0

File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

我相信在这行你所要求的列出了用户的图片目录。尝试将null设置为这样:

File storageDir = getExternalFilesDir(null); 

让我知道,如果这对你有用!祝你好运!

相关问题