Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean history (recent folder) in Android 5+ directory tree picker (ACTION_OPEN_DOCUMENT_TREE)

Directory tree picker created by

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
...

on Android 5+ saves all picked directories history to the Recent folder:

enter image description here

...

Is there a way how to erase this history?

like image 367
Quark Avatar asked Nov 01 '15 10:11

Quark


1 Answers

The recents history is saved in a database which is located:

/data/data/com.android.documentsui/databases/recents.db

So it's not accessible to the other apps, unless the device is rooted.

There is a ContentProvider (RecentsProvider) that manages the database but unfortunately it isn't exported, so only applications that have the same user ID (UID) as the provider will have access to it [1].

There is also a BroadcastReceiver (PackageReceiver) that controls the ContentProvider and purge the recents but unfortunately it only receives ACTION_PACKAGE_FULLY_REMOVED[2] and ACTION_PACKAGE_DATA_CLEARED [3]. Both the intent are protected and they can only be sent by the system.

tl;dr Unfortunately you can't clean the recents. The only viable solution is to clear the whole data of Documents app, but in this case every settings will be lost.

like image 179
Mattia Maestrini Avatar answered Nov 20 '22 17:11

Mattia Maestrini