skip to Main Content

I am using this code to download the file and I want to save the file into the another app’s private data directory how I can do that
`private void initiateFileDownload(String fileUrl) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(fileUrl));
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setTitle("File Download");
request.setDescription("Downloading file…");

String fileName = fileUrl.substring(fileUrl.lastIndexOf(‘/’) + 1);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);

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

I want a slotuion for above my problem

2

Answers


  1. As far as i know Android prevents you from doing exactly that for security reasons, so unless your device is rooted i can’t imagine any way for you to archieve this.

    Login or Signup to reply.
  2. You need some permissions to write to various directories.
    Your app can have certain permissions, see for example
    this post where sdcard is considered.

    It is unusual for an application to have permissions to write to other applications’ directories.

    Unless you are able to give your application very excessive permissions (rooted device?), I think you will need to find some other way to communicate with the other application.

    May be you want just to open the file by the other app? May something like this ?

    As for Environment.DIRECTORY_DOWNLOADS, this post notes you need android.permission.WRITE_EXTERNAL_STORAGE

    This link explains (or un-explains) how the other application can give you permissions to certain directory or file. This would be possible if you are the author of the other application.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search