2016-07-04 13 views
2

urlからダウンロードビデオ用のThinDownloadManagerライブラリを使用しています。動画を非公開にする必要があるので、私はinternal storageを使ってビデオをダウンロードしてプライベートにすることをお勧めします。上で使用されたライブラリでは、私たちが提供する2つのもの、最初はURLであり、2番目はビデオファイルを保存するパスです。内部パスを与えると例外が発生し、video onDownloadFailedメソッドが呼び出されます。ava.io.IOException:オープンに失敗しました:EACCES(許可が拒否されました)

以下は、私が外部ストレージのパスが正常に動作して提供すると以下の私のlogcatエラー

java.io.IOException: open failed: EACCES (Permission denied) 
at java.io.File.createNewFile(File.java:946) 
at com.thin.downloadmanager.DownloadDispatcher.transferData(DownloadDispatcher.java:213) 
at com.thin.downloadmanager.DownloadDispatcher.executeDownload(DownloadDispatcher.java:142) 
at com.thin.downloadmanager.DownloadDispatcher.run(DownloadDispatcher.java:81) 
0Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied) 
at libcore.io.Posix.open(Native Method) 
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) 
at java.io.File.createNewFile(File.java:939) 

である私のコード

public void startVideoDownloading() { 
     //Show downloading in notification bar 

     final NotificationManager mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); 
     mBuilder.setContentTitle("Video downloading") 
       .setContentText("Download in progress") 
       .setSmallIcon(R.drawable.ic_notification); 

     ThinDownloadManager downloadManager = new ThinDownloadManager(); 
     Uri downloadUri = Uri.parse(videoId); 
     File fileDir = createDirectory(); 
     Uri destinationUri = Uri.parse(fileDir + uniqueId); 
     DownloadRequest downloadRequest = new DownloadRequest(downloadUri) 
       .setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH) 
       .setDownloadListener(new DownloadStatusListener() { 
        @Override 
        public void onDownloadComplete(int id) { 
         Toast.makeText(Player.this, "Download Completed", Toast.LENGTH_SHORT).show(); 

         mBuilder.setContentText(" Video download completed") 
           .setProgress(0, 0, false); 
         mNotifyManager.notify(id, mBuilder.build()); 

        } 

        @Override 
        public void onDownloadFailed(int id, int errorCode, String errorMessage) { 
         Toast.makeText(Player.this, "Download Failed", Toast.LENGTH_SHORT).show(); 
         mBuilder.setContentTitle("Failed"); 
         mBuilder.setContentText("Downloading failed") 
           .setProgress(0, 0, false); 
         mNotifyManager.notify(id, mBuilder.build()); 

        } 

        @Override 
        public void onProgress(int id, long totalBytes, long downloadedBytes, int progress) { 
         donutProgress.setProgress(progress); 

         mBuilder.setProgress(100, progress, false); 

         mNotifyManager.notify(id, mBuilder.build()); 

        } 
       }); 
     downloadManager.add(downloadRequest); 
    } 

    public File createDirectory() { 
     File folder = new File(Environment.getDataDirectory() + "/+" + "downloadVideo/"); 
     if (!folder.exists()) { 
      folder.mkdir(); 
      Log.d("TAG","Directory created"); 
     }else { 
      Log.d("TAG","Directory exists"); 
     } 
     return folder; 

    } 

です。どうすればこの問題を解決できますか?あなたが最も可能性が高い(ここで説明するよう:https://developer.android.com/training/basics/data-storage/files.html)マニフェストに次の行を追加する必要が

+0

あなたはmenifest –

+0

@Jinalでの書き込み内部ストレージのための権限を追加する必要があり、私はuが私の許可のようなタイプを提供することができ、書き込み内部storage.Ifの必要性のための権限を追加する必要がないと思います? –

+1

答えて

0

アプリケーションは、Android 6.0以上をターゲットにしている場合

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

はまた、あなたがこの許可を要求する必要があります実行時にユーザー - ここでは詳述:https://developer.android.com/training/permissions/requesting.html

+1

私はすでにmenifestファイルにこの権限を追加しています。 API 20 –

関連する問題