2017-06-11 6 views
0

私はちょうどアンドロイドアプリを開発し始めたので、私はあなたの助けが必要です。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

Try Environment.getExternalStorageDirectory()は、アプリケーション固有のフォルダではなく、デバイスのベースフォルダを取得します。 – pantos27

答えて

0

File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);

私はあなたがユーザーに対して表示されている画像のディレクトリを求めているこの行を信じています。代わりに次のようにnullを実行してみてください:

File storageDir = getExternalFilesDir(null); 

それがうまくいけば教えてください!がんばろう!

関連する問題