2016-03-30 7 views
0

私は問題があるようです。何らかの理由で、私のエミュレータは、一見外見上、青からこのエラーを投げ始めました。java.lang.IllegalStateException: "外部ストレージファイルのディレクトリを取得できませんでした"エミュレータ

java.lang.IllegalStateException: Failed to get external storage files directory 

私は何も変わっていない(私の知っていること)、この影響を受けているだろうことと、実際のデバイス上でテストしている間、それを見つけるの作品。

コードはエラー

public void download(){ 
    DownloadManager.Request request = new DownloadManager.Request(Uri.parse(groups)); 
    request.setTitle("groups.txt"); 
    request.setDescription("File is being downloaded....."); 
    request.allowScanningByMediaScanner(); 
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE); 
    request.setDestinationInExternalFilesDir(getApplicationContext(), null, "groups.txt"); 
    request.setVisibleInDownloadsUi(false); 


    DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
    manager.enqueue(request); 
} 

で君たちは、任意のアイデアを持っていますか?

+1

アクティビティのコンテキストを渡すのではなく、 'getApplicationContext()'に渡す理由はありますか?それがあなたの問題を引き起こしている可能性があります。 – NoChinDeluxe

答えて

0

setDestinationInExternalFilesDir関数では、ディレクトリパス= nullを設定しています。したがって、groups.txtが格納されているディレクトリを見つけることができません。また、私はなぜあなたが活動のコンテキストの代わりにアプリケーションのコンテキストを送信する必要があるのか​​分からない。

+0

ベースフォルダに保存したい場合はどうしたらいいですか?また、実際のデバイスではなぜ動作しますか? – MJDude

+0

http://developer.android.com/reference/android/os/Environment.htmlここで利用できるさまざまなオプションを確認し、 – suku

関連する問題