Android: Refreshing the Gallery after saving new images

Code provided by Petrus in another answer works for me on Kitkat (4.4): MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().toString() }, null, new MediaScannerConnection.OnScanCompletedListener() { /* * (non-Javadoc) * @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri) */ public void onScanCompleted(String path, Uri uri) { Log.i(“ExternalStorage”, “Scanned ” + path + “:”); Log.i(“ExternalStorage”, “-> uri=” + uri); } });

Android MediaStore insertVideo

Here is an easy ‘single file based solution’: Whenever you add a file, let MediaStore Content Provider knows about it using sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageAdded))); Main advantage: work with any mime type supported by MediaStore Whenever you delete a file, let MediaStore Content Provider knows about it using getContentResolver().delete(uri, null, null)

API 29 Mediastore Access

I think this is an Android 10 bug, so I’ve filed a report here: https://issuetracker.google.com/issues/147619577 (includes instructions for an emulator test case to reproduce it if that interests you). Please consider starring it to let the Android team know that it affects you. From what I can tell, it only affects files on ‘external’ storage, … Read more

MediaStore.Images.Media.insertImage deprecated

SOLVED The code suggested from @CommonsWare has no problem, except the fact that if you are programming with targetSdkVersion 29, you must add the condition: val contentValues = ContentValues().apply { put(MediaStore.MediaColumns.DISPLAY_NAME, System.currentTimeMillis().toString()) put(MediaStore.MediaColumns.MIME_TYPE, “image/jpeg”) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { //this one put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation) put(MediaStore.MediaColumns.IS_PENDING, 1) } }

Get cover picture by song

I’m not familiar with MusicUtils, however, you should be able to get the cover art from the file itself by using MediaMetadataRetriever. Here is a brief code snippet showing how to use it. The uri referenced is the content uri for the file you want to retrieve the art for. MediaMetadataRetriever mmr = new MediaMetadataRetriever(); … Read more

Create/Copy File in Android Q using MediaStore

NOTE: If you reinstall the app, MediaStore will not recognize the previous-created file any more: Android 11 cannot retrieve files create with MediaStore after the app re-installs, using Intent to let user pick file is the only solution. 1. Create and Write File createAndWriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { ContentValues … Read more

Android: Picasso load image failed . how to show error message

Use builder: Picasso.Builder builder = new Picasso.Builder(this); builder.listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { exception.printStackTrace(); } }); builder.build().load(URL).into(imageView); Edit For version 2.71828 they have added the exception to the onError callback: Picasso.get() .load(“yoururlhere”) .into(imageView, new Callback() { @Override public void onSuccess() { } @Override public void onError(Exception e) { … Read more

MediaStore – Uri to query all types of files (media and non-media)

It is “external” or “internal” although internal (system files) is probably not useful here. ContentResolver cr = context.getContentResolver(); Uri uri = MediaStore.Files.getContentUri(“external”); // every column, although that is huge waste, you probably need // BaseColumns.DATA (the path) only. String[] projection = null; // exclude media files, they would be here also. String selection = MediaStore.Files.FileColumns.MEDIA_TYPE … Read more

Rename file of the Mediastore which is created by app in android 10. Working on Android API 30 but shows error in API 29

java.lang.IllegalArgumentException: Movement of content://media/external/file/116 which isn’t part of well-defined collection not allowed So it is for Android Q not allowed if you use the collection; Uri extUri = MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL); But is is allowed for a ‘well-defined collection’ like: Uri extUri = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL); // Use “Pictures/MyFolder” for RELATIVE_PATH I leave it to you to find other … Read more

How to save an image in Android Q using MediaStore?

Try the next method. Android Q (and above) already takes care of creating the folders if they don’t exist. The example is hard-coded to output into the DCIM folder. If you need a sub-folder then append the sub-folder name as next: final String relativeLocation = Environment.DIRECTORY_DCIM + File.separator + “YourSubforderName”; Consider that the compress format … Read more