Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

In this page you can find the example usage for android.database Cursor getString.

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java

private static List<NameValuePair> getStarredReadNameValuePairs(DatabaseConnection dbConn, Cursor cursor) {
    String subscription_id = cursor
            .getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID));
    String rss_item_id = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_RSSITEM_ID));

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("async", "true"));
    nameValuePairs.add(new BasicNameValuePair("s", dbConn.getRowIdBySubscriptionID(subscription_id)));
    nameValuePairs.add(new BasicNameValuePair("i", rss_item_id));
    return nameValuePairs;
}

From source file:Main.java

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.//w w  w  .j a  v a  2 s .c  om
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 * @author paulburke
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            if (DEBUG)
                DatabaseUtils.dumpCursor(cursor);

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

From source file:Main.java

static public void dumpCursor(Cursor cursor) {
    final String LOG_TAG = "dumpCursor";
    if (cursor != null) {
        Log.d(LOG_TAG, "cursor " + cursor.getCount());
        for (int i = 0; i < cursor.getColumnCount(); i++)
            Log.d(LOG_TAG, "col " + i + " " + cursor.getColumnName(i));

        cursor.moveToFirst();/* www  . j  av a  2 s.  c o m*/
        String[] a = new String[cursor.getColumnCount()];
        while (!cursor.isAfterLast()) {
            for (int i = 0; i < a.length; i++)
                a[i] = cursor.getString(i);
            Log.d(LOG_TAG, Arrays.toString(a));
            cursor.moveToNext();
        }

        cursor.moveToFirst();
    }
}

From source file:Main.java

public static String getAccountType(Context context, long id, String name) {
    try {// w ww  .j  a va 2s. co m
        Cursor cur = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,
                new String[] { ContactsContract.RawContacts.ACCOUNT_TYPE,
                        ContactsContract.RawContacts.ACCOUNT_NAME },
                ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null);
        if (cur != null) {
            String str = "";
            while (cur.moveToNext()) {
                str += cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE));
            }
            //                Log.v("getAccountType", name+" => "+str);
            cur.close();
            Matcher m = accountTypePattern.matcher(str);
            String last = "";
            while (m.find()) {
                last = m.group(1);
            }
            return last;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.langerhans.wallet.ExchangeRatesProvider.java

public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) {
    final String currencyCode = cursor
            .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_CURRENCY_CODE));
    final Coin rateCoin = Coin
            .valueOf(cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN)));
    final Fiat rateFiat = Fiat.valueOf(currencyCode,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT)));
    final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE));

    return new ExchangeRate(new com.dogecoin.dogecoinj.utils.ExchangeRate(rateCoin, rateFiat), source);
}

From source file:Main.java

public static String getAbsoluteImagePath(Activity context, Uri uri) {
    String imagePath = "";
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.managedQuery(uri, proj, // Which columns to
            // return
            null, // WHERE clause; which rows to return (all rows)
            null, // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imagePath = cursor.getString(column_index);
        }//ww w .ja  v  a2 s  . co  m
    }

    return imagePath;
}

From source file:com.coinomi.wallet.ExchangeRatesProvider.java

public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) {
    final String codeId = getCurrencyCodeId(cursor);
    final CoinType type = CoinID.typeFromSymbol(
            cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN_CODE)));
    final Value rateCoin = Value.valueOf(type,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN)));
    final String fiatCode = cursor
            .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT_CODE));
    final Value rateFiat = FiatValue.valueOf(fiatCode,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT)));
    final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE));

    ExchangeRateBase rate = new ExchangeRateBase(rateCoin, rateFiat);
    return new ExchangeRate(rate, codeId, source);
}

From source file:Main.java

private static String fileUriTitle(Context context, String contentUri) {
    String result = null;/*from   ww w  . j  a v  a2s .  c o m*/
    String[] p = { MediaStore.MediaColumns.DISPLAY_NAME, MediaStore.MediaColumns.TITLE };
    Uri uri = Uri.parse(contentUri);
    String path = uri.getPath();
    String last = Uri.parse(path).getLastPathSegment();
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, p, // which columns
            MediaStore.MediaColumns.DISPLAY_NAME + "='" + last + "'", // which rows
            null, // selection args (none)
            null); // order-by clause (ascending by name)
    if (cursor != null) {
        int tcol = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE);
        if (cursor.moveToFirst()) {
            result = cursor.getString(tcol);
        }
    }
    return (result);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String getAbsoluteImagePath(Activity context, Uri uri) {
    String imagePath = "";
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.managedQuery(uri, proj, // Which columns to
            // return
            null, // WHERE clause; which rows to return (all rows)
            null, // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imagePath = cursor.getString(column_index);
        }/*from w ww  .  j  a v  a 2s  .c o  m*/
    }

    return imagePath;
}

From source file:cn.sharesdk.analysis.db.MessageUtils.java

/**
 * ?wifi??*//*from   w  ww  .j a  v a2 s .  c  om*/
private static synchronized ArrayList<MessageModel> getEventMsg(Context c, String selection,
        String[] selectionArgs) {

    ArrayList<MessageModel> group = new ArrayList<MessageModel>();
    MessageModel model = new MessageModel();
    JSONObject jsonObject = new JSONObject();

    String eventID;
    String eventType;
    DBProvider provider = DBProvider.getDBProvider(c);
    Cursor cursor = provider.query(DBHelp.TABLE_STATISTICS,
            new String[] { DBHelp.COLUMN_ID, DBHelp.COLUMN_EVENT_TYPE, DBHelp.COLUMN_EVENT_DATA }, selection,
            selectionArgs, null);
    try {
        while (cursor != null && cursor.moveToNext()) {

            eventID = cursor.getString(0);
            eventType = cursor.getString(1);
            JSONObject eventObject = new JSONObject(cursor.getString(2).toString());
            model.idList.add(eventID);
            if (jsonObject.has(eventType)) {
                JSONArray existArray = jsonObject.getJSONArray(eventType);
                existArray.put(eventObject);
            } else {
                JSONArray newArray = new JSONArray();
                newArray.put(0, eventObject);
                jsonObject.put(eventType, newArray);
            }

            if (model.idList.size() == 50) {
                //?,??
                model.data = jsonObject.toString();
                group.add(model);
                model = new MessageModel();
                jsonObject = new JSONObject();
                continue;
            }
        }
        cursor.close();

        //?10????\n?
        if (model.idList.size() != 0) {
            model.data = jsonObject.toString();
            group.add(model);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return group;

}