2017-06-11 118 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); 

讓我知道,如果這對你有用!祝你好運!

相關問題