mocode10
mocode10

Reputation: 598

Android clear download manager history without deleting file

I use the download manager to download a file and install it.

I'm curious if there is a way to remove it from the downloads history without actually deleting the file from disk?

As far as I know there is no callback to tell if the user installed the file or not so I would like to leave it on disk, but remove it from the downloads history only.

Here is my download code:

// Create download manager final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(appURL));

    // Save to here
    request.setDestinationUri(this.apkUri);

    // Retrieve system download service
    final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);

    // Queue request
    manager.enqueue(request);

    // Will fire off and perform installation when download completes
    BroadcastReceiver onComplete = new BroadcastReceiver()
    {
        @Override
        public void onReceive(Context ctxt, Intent intent)
        {
            performInstall();
            ctxt.unregisterReceiver(this);
            //finish();
        }
    };

    context.registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

And one other thing I'm curious about is in my broadcast receiver is finish() necessary? I'm calling this from a helper class so I can't access the finish function inside of it for some reason.

Upvotes: 0

Views: 1084

Answers (1)

nipil
nipil

Reputation: 86

Before queueing :

  • Add a suffix ".download" to download local path

OnReceive callback :

  • get local uri from DM download column (src)
  • remove ".download" suffix from Uri (dst)
  • rename "src" to "dst"
  • remove ID from download manager

Result : file still on disk and DM cleaned

Upvotes: 0

Related Questions