mediastore
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
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) } }
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
Get list of photo galleries on Android
Groupings are defined by MediaStore.Images.Media.BUCKET_DISPLAY_NAME. Here is the sample code to list the images and log their bucket name and date_taken: // which image properties are we querying String[] projection = new String[] { MediaStore.Images.Media._ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN }; // content:// style URI for the “primary” external storage volume Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Make the … Read more
How can I refresh MediaStore on Android?
Here is an easy to use ‘single file based‘ solution: Adding a file: Whenever you add a file, inform MediaStore’s Content Provider using: sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(newMediaFile))); Deleting a file: Similarly, when you delete a file, inform MediaStore’s Content Provider using: getContentResolver().delete(uri, null, null) // (Credit goes to [DDSports][1])
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