android / storage-samples Goto Github PK
View Code? Open in Web Editor NEWMultiple samples showing the best practices in storage APIs on Android.
License: Apache License 2.0
Multiple samples showing the best practices in storage APIs on Android.
License: Apache License 2.0
Hyperlinks are not declared properly.
It should be like
How to get hidden folder using MediaStore
At MediaStoreFragment line 50, there is redundant line.
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
...
binding.recyclerView
...
return binding.root
}
2019-09-08 02:20:34.585 28158-28158/com.example.android.contentproviderpaging E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.contentproviderpaging, PID: 28158
java.lang.RuntimeException: Unable to get provider com.example.android.contentproviderpaging.ImageProvider: java.lang.ClassNotFoundException: Didn't find class "com.example.android.contentproviderpaging.ImageProvider" on path: DexPathList[[zip file "/data/app/com.example.android.contentproviderpaging-OXltTdAm2A1a4Aqc-7OZuA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.contentproviderpaging-OXltTdAm2A1a4Aqc-7OZuA==/lib/arm64, /system/lib64, /system/product/lib64]]
at android.app.ActivityThread.installProvider(ActivityThread.java:6988)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.contentproviderpaging.ImageProvider" on path: DexPathList[[zip file "/data/app/com.example.android.contentproviderpaging-OXltTdAm2A1a4Aqc-7OZuA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.contentproviderpaging-OXltTdAm2A1a4Aqc-7OZuA==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
at android.app.ActivityThread.installProvider(ActivityThread.java:6972)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6528)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6445)
at android.app.ActivityThread.access$1300(ActivityThread.java:219)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1859)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Issue by anmolvermamm
Friday Sep 28, 2018 at 13:25 GMT
Originally opened as googlearchive/android-StorageProvider#6
I have an implementation of document provider, why is it that the cancellation signal is always null, when someone tries to opendocument from documentprovider ?
Thanks for your time!
Issue by commonsguy
Sunday Apr 14, 2019 at 19:41 GMT
Originally opened as googlearchive/android-SharingShortcuts#2
Steps to Reproduce:
Expected Results: for the app to build
Actual Results: the app fails with compile errors on references to Intent.EXTRA_SHORTCUT_ID
, as that is new to Android Q but the Application
module's compileSdkVersion
is 28
Workaround: change Application/build.gradle
to use compileSdkVersion 'android-Q'
What is the bestway to pick a video file and get real path to upload to server. Seems from Android 10, it is very hard.
Issue by DILEEP-YADAV
Monday Sep 25, 2017 at 13:27 GMT
Originally opened as googlearchive/android-ContentProviderPaging#1
Hi! Please help ! How to sharing data between two app using intent and get result with onActivityResult ?
Hello,
I have researched how to solve this "issue" in the documentation and on the web, but unfortunately was not able to find anything.
We are currently running the Android 11 In the project I am working on, we have the all files permissions in the code, so everytime the application starts on a new device, it will ask for the permissions. However, in Android 12, instead of displaying only the application that is requesting all files permissions, it displays all the applications when our application is requesting access.
It is important to highlight that our code is following Android's documentation and we are using the ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
Is there a way to prevent this behaviour just displaying our app's permissions? We want to avoid this behaviour, since users can change the settings for other app's and that's potentially dangerous for our user.
Thanks in Advance
uri: content://[email protected]/union/video/item/25473
stack:
cause by:
java.io.FileNotFoundException: Unable to get item com.sec.android.gallery3d.data.UnionSCloudVideo@882a3ac
android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:144)
android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:698)
android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1416)
android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1253)
android.content.ContentResolver.openInputStream(ContentResolver.java:973)
device:
SM-G9350;Android 8.0.0,level 26
permission:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
this happed on Samsung device.
Issue by writtmeyer
Thursday Mar 14, 2019 at 21:13 GMT
Originally opened as googlearchive/android-SharingShortcuts#1
The previous setting of "android-Q" prevented the app from being
installable
writtmeyer included the following code: https://github.com/googlesamples/android-SharingShortcuts/pull/1/commits
I have android device which is rooted. I need to perform Runtime.getRuntime().exec("su") .and I have added READ_LOGs permission in manifest also. But even though i have root device its still gives me access denied. I have seen most of the blogs still the issue remains same. Can you please tell me Is there anything missing here
Use case - Currently I'm working on video uploading module. To get the video i have fired SFA video picker intent but I can't get any way or code to get the video details from uri in OnActivityResult even i have watched Google IO 19 Preparing Scoped Storage Video but there also not provided any sample code how to do that. ( Video details mean duration size name resolution and name )
To get the video details we have to use MediaStore api which recommended one and MediaStore only works with content URIs if i pass file uri then cursor will be always null
and we only get the content uri when cursor isnot null
Hoping to will answer my question someone
can the onActivityResult Deprecated be fixed / updated!?
I've been following latest documentation and tried to open the files after all permissions check mentioned in the docs. I thought I might be missing something, ergo, after checking the FileManager sample, it seems openFile()
extension from FileManager sample is also helpless in opening the file. I tried to open a word file (.docx) an image file, a pdf file. It opens the app but the file can't be found and (Adobe Reader, Word and Gallery shows the main screen).
Tested with Realme 5 Pro (Android 10) with all permissions granted
fun openFile(activity: AppCompatActivity, selectedItem: File) {
// Get URI and MIME type of file
val uri = Uri.fromFile(selectedItem).normalizeScheme()
val mime: String = getMimeType(uri.toString())
// Open file with user selected app
val intent = Intent()
intent.action = Intent.ACTION_VIEW
intent.data = uri
intent.type = mime
return activity.startActivity(intent)
}
Pressing the "Clear Files" button deletes the Images Folder without it ever being recreated.
This causes a java.io.FileNotFoundException for all the other buttons until the app is relaunched, at which time the Images Folder is recreated again.
I would like to submit a fix.
android 11 /storage/emulated/0/Download/Driver.apk: open failed: EACCES (Permission denied)
See here:
#16 (comment)
Issue by kyunghoj
Wednesday Jul 06, 2016 at 19:10 GMT
Originally opened as googlearchive/android-StorageProvider#3
writeDummyFilesToStorage()
checks mBaseDir
directory for an existing sub-directory to see if sample files have been already copied. But with a newer Android Studio, if instant-run is enabled, there is actually a directory named instant-run/
, so this code does not copy sample image files.
2020-03-22 19:34:53.585 23637-23637/com.android.samples.mediastore E/AndroidRuntime: FATAL EXCEPTION: main Process: com.android.samples.mediastore, PID: 23637 java.lang.IllegalStateException: displayName must not be null at com.android.samples.mediastore.MainActivityViewModel$queryImages$2.invokeSuspend(MainActivityViewModel.kt:193) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594) at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
I am studying Documents Providers and I have found something that I cannot understand, which also happens with the "StorageProvider" example of this repository.
It appears that all functions are called more than once when I open SAF.
I report the logcat:
When I first open SAF:
2020-05-27 19:57:45.888 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:57:45.971 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryChildDocuments, parentDocumentId: root: sortOrder: _display_name ASC
2020-05-27 19:57:45.990 20322-20362/com.example.android.storageprovider V/MyCloudProvider: queryChildDocuments, parentDocumentId: root: sortOrder: _display_name ASC
2020-05-27 19:57:46.036 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.078 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.093 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
2020-05-27 19:57:46.109 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocumentThumbnail
When I open a file (eg a photo with Google Foto):
2020-05-27 19:58:01.127 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.273 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.306 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.344 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.345 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.381 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.775 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.810 20322-20341/com.example.android.storageprovider V/MyCloudProvider: queryDocument
2020-05-27 19:58:01.843 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.849 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.854 20322-20341/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
2020-05-27 19:58:01.868 20322-20362/com.example.android.storageprovider V/MyCloudProvider: openDocument, mode: r
Is it normal for queryDocument() and openDocument () to be called so many times?
That way, if my document provider were to download a file over the network, wouldn't it be downloaded multiple times?
I'm working on a file manager application. When I call API --- File. listFiles() , a crash occurs. Mobile phone manufacturer is vivo -- a china brand.
I had add needed storage permissions for my app, and provide path xml in res folder。
AndroidManifest.xml include the following permissions:
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
path xml( file_provider.xml ) like this:
<cache-path
name="cache"
path="." />
<!-- 应用在被用户卸载后,SDCard/Android/data/应用的包名/ ,这个目录下的所有文件都会被删除-->
<!-- Context.getExternalCacheDir() + "/cache/" -->
<!-- SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据,比如头像-->
<external-cache-path
name="sdcard_cache_path"
path="." />
<!-- Context.getExternalFilesDir(null) + "/path/" -->
<!-- SDCard/Android/data/应用的包名/files/目录 ,一般放一些长时间保存的数据,比如语音,视频,发送的图片,文件-->
<external-files-path
name="sdcard_file_path"
path="." />
<!-- 代表Environment.getExternalStorageDirectory() + "/path/" -->
<!-- path设置为'.'时代表整个存储卡 Environment.getExternalStorageDirectory() + "/path/" -->
<external-path
name="sdcard_root_path"
path="." />
<!-- Context.getFilesDir() + "/path/" -->
<!-- 此处为 data/data/包名/files/path -->
<files-path
name="files"
path="." />
<!-->应用存储目录<-->
<!-- 代表设备的根目录new File("/")-->
<!-- 此处为 ./ -->
<root-path
name="root_path"
path="" />
I am using Files.copy
API (Package: java.nio.file
) for copying images to new directory. The operation is working fine and I can see files are copied properly in new directory. But those newly copied files are not visible in Gallery by default.
If if use default file manager and try to move those newly copied files again in new folder then that new folder is immediately visible in phone gallery.
Do I need any change here? or I am missing something ?
Code snippet which I am using:
for (Path srcPath : sourcePaths) {
String fileName = srcPath.getFileName().toString();
File targetFile = new File(SDCARD_PATH + TARGET_PATH + fileName);
if (!fileName.equalsIgnoreCase(".nomedia") && !targetFile.exists()) {
Files.copy(srcPath, targetFile.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
}
}
This repository was archived:
https://github.com/googlearchive/android-DirectShare
and the only link it says it moved to is here, but I don't see any sample of it here.
Also, there was a rumor that Google works on a new sharing technique of files, that will replace Android-Beam. Maybe it's a good idea to show how to use it here too?
Issue by diceroll123
Wednesday Aug 19, 2015 at 08:32 GMT
Originally opened as googlearchive/android-StorageProvider#1
It's way too much work to fill out a CLA or anything like that, it's after 4 AM in the morning. My brain's not cut out for that right now.
Though this example is not what I was looking for, just gonna leave this issue here. 😃
Android Studio won't build newest build because it uses AppCompat, try adding compile "com.android.support:appcompat-v7:23.0.0"
to the dependencies in the Application
build.gradle
. 👍
You may have this issue elsewhere that auto-updates builds like this.
Made an issue here because the link under Support is broken.
If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-MyCloud
gh pr checkout 109
I have implemented this sample in my project... Everything was ok but when I try to convert the content uri to File to upload the image to server.. it throws an error.....
Security Exception. In Android 10
If I enable legacy in androidmanifest.xml file then it is ok...
If it shows a security exception why u make this sample recently?
What is the alternative...what is the uses of this sample if i can't use the image I pick?????
In the module ActionOpenDocument
, there's no PERMISSIONS declared in AndroidManifest.xml
.
Does that mean we have the access to all URI returned by system chooser?
Like Intent.ACTION_PICK
, Intent.ACTION_GET_CONTENT
,Intent.ACTION_OPEN_DOCUMENT
etc.
I can not find any official info about this.
What I've implemented is choose an image from gallery then set it to an ImageView.
Tested on several devices it works fine. (Pixel 3 Android 12, Samsung S8 Android 7, ...)
Only one Chinese Model(Android 8.1) crashed and reported SecurityException
.
Platform:Android 9
--------- beginning of crash
2020-08-20 18:09:48.210 28937-28937/com.android.samples.mediastore E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.android.samples.mediastore, PID: 28937
java.lang.IllegalStateException: displayName must not be null
at com.android.samples.mediastore.MainActivityViewModel$queryImages$2.invokeSuspend(MainActivityViewModel.kt:197)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:740)
2020-08-20 18:09:48.221 28937-28937/com.android.samples.mediastore I/Process: killProcess pid=28937
java.lang.RuntimeException
at android.os.Process.killProcess(Process.java:1005)
at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:157)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at kotlinx.coroutines.android.AndroidExceptionPreHandler.handleException(AndroidExceptionPreHandler.kt:40)
at kotlinx.coroutines.CoroutineExceptionHandlerImplKt.handleCoroutineExceptionImpl(CoroutineExceptionHandlerImpl.kt:30)
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:33)
at kotlinx.coroutines.StandaloneCoroutine.handleJobException(Builders.common.kt:184)
at kotlinx.coroutines.JobSupport.tryFinalizeFinishingState(JobSupport.kt:226)
at kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath(JobSupport.kt:849)
at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:811)
at kotlinx.coroutines.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:787)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:111)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:334)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:196)
at android.app.ActivityThread.main(ActivityThread.java:7334)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
In the MediaStore sample we currently load images in onResume
, which isn't really best practice. We should switch to creating a ContentObserver
and using the callbacks from it to update the LiveData
.
I installed MediaStore V1.0 onto my Android running V10
I selected an image to delete from the images displayed within the app, clicked delete and the image appeared to be deleted. However, when I then opened the phone's default image viewer the image was still there. On opening the file explorer I could still see the file: /storage/sdcard0/DCIM/Camera/IMG_20210119_190148.jpg when viewing by folder, but the image was missing when viewing by image type.
When I returned to the MediaStore app, the file was no longer visible. It therefore appears that some reference to the image file is deleted, and not the actual file.
seems that just update this line in action script to 1.11 would make it work. But needs to make sure other samples could take it.
Hi Android Team
Thanks for sharing android examples projects.
I'm using Android 4.0.1 and opening this project:
https://github.com/android/storage-samples/tree/master/FileProvider
Without any modification, the generated apk on my Android 10.0 phone, started smoothly, but after selecting any existing image, or after taking photo using system camera, this "Gary Gallery" app just crash.
Some consumers of DocumentsProviders (like the Files app on Chrome OS) require these functions to provide full functionality. These functions should be added to the official sample for testing and reference.
Issue by lbtrace
Wednesday Jul 18, 2018 at 09:03 GMT
Originally opened as googlearchive/android-StorageProvider#5
Code path: \Application\src\main\java\com\example\android\storageprovider\MyCloudProvider.java
public Cursor queryRecentDocuments(String rootId, String[] projection)
throws FileNotFoundException {
......
// Create a queue to store the most recent documents, which orders by last modified.
PriorityQueue<File> lastModifiedFiles = new PriorityQueue<File>(5, new Comparator<File>() {
public int compare(File i, File j) {
return Long.compare(i.lastModified(), j.lastModified());
}
});
......
// Add the most recent files to the cursor, not exceeding the max number of results.
for (int i = 0; i < Math.min(MAX_LAST_MODIFIED + 1, lastModifiedFiles.size()); i++) {
final File file = lastModifiedFiles.remove();
includeFile(result, null, file);
}
return result;
}
In for code segment, lastModifiedFiles.remove()
will modify PriorityQueue size, so lastModifiedFiles.size()
always change, this is logic error.
Currently the StorageProvider sample does allow for the creation of directories, it makes an empty file.
After trying Toggle pending status for media files from official docs:
https://developer.android.com/training/data-storage/shared/media#toggle-pending-status
I get exception:
java.lang.IllegalArgumentException: Movement of content://media/external_primary/video/media which isn't part of well-defined collection not allowed
at android.content.ContentProviderProxy.update(ContentProviderNative.java:578)
It was possible before using file-path, but now I can't see of a way to do it, to get various APK information on the file system, such as app-icon and app-name:
Forcing us to use SAF (on Q) instead of storage permission should also offer us alternatives to all of the Android framework functions.
As the title, is there any sample or way that I can query with some relative path?
I know we can do it when inserting, but when searching, can we do the same thing?
Sometimes we would prefer to show some apps before others, and sometimes only very specific apps.
This was possible before using EXTRA_INITIAL_INTENTS , but for some reason it seems it can show now only up to 2 items and that's it. No customization potential as before.
I hope I'm wrong about this, so please share a sample of how to do it, just like before Android Q.
Previously, we could use EXTRA_INITIAL_INTENTS to choose exactly which exact intents items to show, and in which order:
https://stackoverflow.com/a/41140508/878126
How can we do the same now when choosing to share?
On Q, now when I use EXTRA_INITIAL_INTENTS, it can show only up to 2 items, and that's it. Can't show more than that, and it's terrible.
Here's what happens when I try to show 3 items, of "com.ghisler.android.TotalCommander", "com.google.android.gm","com.whatsapp" :
Issue by kyunghoj
Wednesday Jul 06, 2016 at 19:12 GMT
Originally opened as googlearchive/android-StorageProvider#4
Fix for the issue #3 regarding a problem with the instant-run feature.
kyunghoj included the following code: https://github.com/googlesamples/android-StorageProvider/pull/4/commits
I am learning android and I seen your example, and I implemented my provider in my first application
https://github.com/DarioLobos/sistemariego
but when I erase files using the file manager In my list of UI files still are showed. I try to clean it using NotifyChanges without any implementation that can update the list For example this.:
context = root.getContext();
Uri emptyUri= DocumentsContract.buildRootUri(AUTORITY, EMPTY);
(this Is a root with only the id empty and column MY_TYPE_DIR, trying to clean thelist)
context.getContentResolver().notifyChange(emptyUri,null);
Uri rootUri = DocumentsContract.buildRootUri(AUTORITY, ROOT);
ContentObserver observer = new ContentObserver(null) {
@Override
public boolean deliverSelfNotifications() {
return super.deliverSelfNotifications();
}
};
context.getContentResolver().notifyChange(rootUri,observer);
context.getContentResolver().registerContentObserver(rootUri,true,observer);
observer.dispatchChange(true,rootUri);
Uri documentsInRoot = DocumentsContract.buildSearchDocumentsUri(AUTORITY, ROOT,"");
I did it in the fragment that use to request the save open file. BUT DONT ERASE THE GOST FILES ERASED FROM FILE MANAGER IN ANY WAY.
Do you have any example to clean the erased files from other apps ? Many thanks in advance.
I'm trying to delete audio files (that were copied to the device from USB) from the external storage.
After analyzing the MediaStore
sample, I ended up with the following solution for API 28 and earlier:
fun deleteTracks(trackIds: LongArray): Int {
val whereClause = buildWildcardInClause(trackIds.size) // _id IN (?, ?, ?, ...)
return resolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, whereClause, Array(trackIds.size) { trackIds[it].toString() })
}
I noticed that the above code only deletes tracks from the MediaStore database and not from the device (files are re-added to the MediaStore after rebooting). So I modified that code to query the Media.DATA
column, then use that information to delete the associated files. This works as intended.
But now that Android Q introduced scoped storage, Media.DATA
(and Albums.ALBUM_ART
) are now deprecated because the app may be unable to access those files. ContentResolver.openFileDescriptor
can only be used to read files, not delete them.
Then what is the recommended way to delete tracks as of Android Q ?
The sample does not show how to delete multiple files from the MediaStore
, and MediaStore.Audio.Media
seems to work differently than MediaStore.Images.Media
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.