Android ContentResolver Read getContentFromProvider( ContentResolver contentResolver, Uri uri, String[] valueTypes)

Here you can find the source of getContentFromProvider( ContentResolver contentResolver, Uri uri, String[] valueTypes)

Description

get Content From Provider

Declaration

public static JSONArray getContentFromProvider(
            ContentResolver contentResolver, Uri uri, String[] valueTypes) 

Method Source Code

//package com.java2s;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.ContentResolver;

import android.database.Cursor;

import android.net.Uri;

public class Main {
    public static JSONArray getContentFromProvider(
            ContentResolver contentResolver, Uri uri, String[] valueTypes) {
        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
                                .getColumnIndex(valueTypes[i]));
                        obj.put(valueTypes[i], value);
                    }//from  w ww  .j av  a  2  s.c  o  m
                    array.put(obj);

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }

        return array;
    }
}

Related

  1. fileUriToBase64(Uri uri, ContentResolver resolver)
  2. readBytes(Uri uri, ContentResolver resolver)
  3. getExifOrientation(ContentResolver cr, Uri uri)