List of utility methods to do ContentResolver Read
String | fileUriToBase64(Uri uri, ContentResolver resolver) File uri to base64. String encodedBase64 = ""; try { byte[] bytes = readBytes(uri, resolver); encodedBase64 = Base64.encodeToString(bytes, 0); } catch (IOException e1) { e1.printStackTrace(); return encodedBase64; ... |
byte[] | readBytes(Uri uri, ContentResolver resolver) Read bytes. InputStream inputStream = resolver.openInputStream(uri); ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; int len = 0; while ((len = inputStream.read(buffer)) != -1) { byteBuffer.write(buffer, 0, len); return byteBuffer.toByteArray(); |
JSONArray | getContentFromProvider( ContentResolver contentResolver, Uri uri, String[] valueTypes) get Content From Provider Cursor cursor = contentResolver.query(uri, null, null, null, null); JSONArray array = new JSONArray(); if (cursor != null) { while (cursor.moveToNext()) { try { JSONObject obj = new JSONObject(); for (int i = 0; i < valueTypes.length; i++) { String value = cursor.getString(cursor ... |
int | getExifOrientation(ContentResolver cr, Uri uri) get Exif Orientation int degree = 0; if (uri.getScheme().equals("content")) { String[] projection = { Images.ImageColumns.ORIENTATION }; Cursor c = cr.query(uri, projection, null, null, null); if (c.moveToFirst()) { degree = c.getInt(0); } else if (uri.getScheme().equals("file")) { ... |