3

I would like to clear both cache and data of default download manager app through code. Is it possible? I need this because manually clearing download manager data is giving more successful downloads from my app. Is it possible to delete cache or data of other app from our application?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ganesh K
  • 2,623
  • 9
  • 51
  • 78
  • http://developer.android.com/reference/android/app/DownloadManager.html that's the one I now only about remove() method there. – Sergey Benner Feb 22 '12 at 11:52
  • @SergeyBenner remove() not really removing data it is just canceling that particular download. Tx for u response – Ganesh K Feb 22 '12 at 11:57
  • 1
    You might also want to check this class http://hi-android.info/src/android/provider/Downloads.java.html and http://blog.lytsing.org/archives/135.html and taken from there `getContentResolver().delete(Downloads.CONTENT_URI, "(" + Downloads.TITLE + " = 'screenshot')", null);` – Sergey Benner Feb 22 '12 at 12:21
  • aye i know if it's downloaded it doesn't remove the file on the storage – Sergey Benner Feb 22 '12 at 12:24

1 Answers1

0

from the comment of @Sergey Benner following the code form blog.lytsing.org/archives/135.html and taken from there getContentResolver().delete(Downloads.CONTENT_URI, "(" + Downloads.TITLE + " = 'screenshot')", null);

As android.provider.Downloads is private class so we can not reference it directly, so I replaced the constants with strings taken from the class https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/provider/Downloads.java

getContentResolver().delete(Uri.parse("content://downloads/my_downloads"),"(" + "title" + " = 'Your download title')", null);

By using this I am able to clear some data from Download manager.

Please note I applied it in app signed with systems keys.

Dev
  • 817
  • 10
  • 16