I am using ThinDownloadManager
library for download video from url
. There is need to make video private so I like to use internal storage
for saving downloading video to make it private. In above used library two thing we provide, first is url and second is path to store video file. when i give internal path it arise exception and video onDownloadFailed method invoked.
Below is my code
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;
}
below is my logcat error
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)
When i provide external storage path is working fine. How can i resolve this problem?