Insertion of thousands of contact entries using applyBatch is slow

Use ContentResolver.bulkInsert (Uri url, ContentValues[] values) instead of ApplyBatch() ApplyBatch (1) uses transactions and (2) it locks the ContentProvider once for the whole batch instead locking/unlocking once per operation. because of this, it is slightly faster than doing them one at a time (non-batched). However, since each Operation in the Batch can have a different … Read more

A final answer on how to get Exif data from URI

To expand on alex.dorokhov’s answer with some sample code. The support library is a great way to go. build.gradle dependencies { … compile “com.android.support:exifinterface:25.0.1” … } Example code: import android.support.media.ExifInterface; … try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) { ExifInterface exif = new ExifInterface(inputStream); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); } catch (IOException e) { e.printStackTrace(); } The … Read more

using ContentProviderClient vs ContentResolver to access content provider

Your android device has many databases, each of which is identified by a unique Content Authority. This is the “domain name” equivalent part in the content:// uri — everything before the first slash. ContentResolver stores data providing a mapping from String contentAuthority to ContentProvider. When you call ContentResolver.query() or update() or what have you, the … Read more

Convert content:// URI to actual path in Android 4.4

This will get the file path from the MediaProvider, DownloadsProvider, and ExternalStorageProvider, while falling back to the unofficial ContentProvider method you mention. /** * Get a file path from a Uri. This will get the the path for Storage Access * Framework Documents, as well as the _data field for the MediaStore and * other … Read more

Android Gallery on Android 4.4 (KitKat) returns different URI for Intent.ACTION_GET_CONTENT

This requires no special permissions, and works with the Storage Access Framework, as well as the unofficial ContentProvider pattern (file path in _data field). /** * Get a file path from a Uri. This will get the the path for Storage Access * Framework Documents, as well as the _data field for the MediaStore and … Read more

tech