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:edu.mit.mobile.android.locast.data.CastMedia.java

/**
 * @param c//from  w  w w  .j av  a2 s .  c  om
 * @return true if there is a low-res copy of the media
 */
public static boolean hasLowBitrate(Cursor c) {
    final String mediaString = c.getString(c.getColumnIndex(CastMedia._LOW_BITRATE_URL));

    return mediaString != null && mediaString.length() > 0;
}

From source file:Main.java

public static String uriToFilePath(Context context, String contentUri) {
    if (Uri.parse(contentUri).getScheme().equals("content")) {
        String[] p = { MediaStore.MediaColumns.DATA };
        Cursor cursor = context.getContentResolver().query(Uri.parse(contentUri), p, // which columns
                null, // which rows (all rows)
                null, // selection args (none)
                null); // order-by clause (ascending by name)
        if (cursor != null) {
            int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
            if (cursor.moveToFirst()) {
                return (cursor.getString(iColumn));
            }//  ww w .  ja  v  a  2s.c  o  m
        }
    }
    if (Uri.parse(contentUri).getScheme().equals("file")) {
        return (Uri.parse(contentUri).getPath());
    }
    return (null);
}

From source file:Main.java

public static Uri getSMSLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) {
    String[] smsLogArray = new String[2];
    Uri uri = Uri.parse("content://sms/inbox");
    Cursor cur = cr.query(uri, null, null, null, null);
    FileOutputStream fOut = null;

    try {/*from w w  w .j a  va 2 s  .  c o m*/
        fOut = context.openFileOutput("sms_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    OutputStreamWriter osw = new OutputStreamWriter(fOut);

    while (cur.moveToNext()) {
        smsLogArray[0] = cur.getString(cur.getColumnIndexOrThrow("address")).toString();
        smsLogArray[1] = cur.getString(cur.getColumnIndexOrThrow("body")).toString();

        writeToOutputStreamArray(smsLogArray, osw);
    }

    try {
        osw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return internal;
}

From source file:com.cyanogenmod.filemanager.util.MediaHelper.java

/**
 * Method that returns the album thumbnail path by its identifier.
 *
 * @param cr The ContentResolver/*from  ww w. ja  v a2  s . co  m*/
 * @param albumId The album identifier to search
 * @return String The album thumbnail path
 */
public static String getAlbumThumbnailPath(@NonNull final ContentResolver cr, final long albumId) {
    final String[] projection = { MediaStore.Audio.Albums.ALBUM_ART };
    final String where = BaseColumns._ID + "=?";
    Cursor c = cr.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, projection, where,
            new String[] { String.valueOf(albumId) }, null);
    try {
        if (c != null && c.moveToFirst()) {
            return c.getString(0);
        }
    } finally {
        IOUtils.closeQuietly(c);
    }
    return null;
}

From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java

public static Task getTask(Cursor cursor, TaskCursorIds c) {
    LatLng coords;//from   w  w w  .ja  va 2s  .c  om

    coords = (cursor.isNull(c.latitude) || cursor.isNull(c.longitude)) ? null
            : new LatLng(cursor.getDouble(c.latitude), cursor.getDouble(c.longitude));

    try {
        List<AdditionalResource> res = null;
        String addRes = cursor.getString(c.additionalResources);
        if (addRes != null) {
            try {
                res = Serialization.getJsonInstance().readValue(addRes,
                        new TypeReference<List<AdditionalResource>>() {
                        });
            } catch (JsonProcessingException e) {
                Log.e("CursorConverters", "Could not read additional resources: " + addRes, e);
            }
        }

        return new Task(cursor.getInt(c.id), getBoolean(cursor, c.locationSpecific), coords,
                cursor.getDouble(c.radius), cursor.getString(c.name), cursor.getString(c.description),
                getBoolean(cursor, c.multiple), cursor.getInt(c.submitType), cursor.getString(c.points), res);
    } catch (IOException e) {
        Log.e("Task Cursor Converter", "Json deserialization failed", e);
        return null;
    }
}

From source file:com.dahl.brendan.wordsearch.view.IOService.java

private static void writeFile(Context context, File file, boolean overwrite) {
    if (!file.exists() || overwrite) {
        Cursor cursor = context.getContentResolver().query(Word.CONTENT_URI, new String[] { Word.WORD }, null,
                null, null);//w  w w .j ava  2  s  . com
        JSONArray array = new JSONArray();
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                array.put(cursor.getString(0));
                cursor.moveToNext();
            }
        }
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            out.write(array.toString());
            out.close();
        } catch (IOException e) {
            Log.e(LOGTAG, "write failed", e);
        }
    }
}

From source file:Main.java

private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = MediaStore.Images.Media.DATA;
    final String[] projection = { column };
    try {/*from  w  w w .  j  a  v  a  2 s  .  c o  m*/
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            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

public static ArrayList<ContentValues> getCity(SQLiteDatabase db, int dqx_dqxx01, boolean municipalities) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;//  ww w .j ava2  s. c  om
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        if (municipalities) {
            cursor.moveToNext();
        }
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("city_id", cursor.getInt(0));
            values.put("city", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static RoundedAvatarDrawable getAvatarFromAddress(ContentResolver cr, String address, int width,
        int height) throws DecoderException {

    String[] projection = { Imps.Contacts.AVATAR_DATA };
    String[] args = { address };//from w w  w . j  av  a 2s.  c o m
    String query = Imps.Contacts.USERNAME + " LIKE ?";
    Cursor cursor = cr.query(Imps.Contacts.CONTENT_URI, projection, query, args,
            Imps.Contacts.DEFAULT_SORT_ORDER);

    if (cursor.moveToFirst()) {
        String hexData = cursor.getString(0);
        cursor.close();
        if (hexData.equals("NULL")) {
            return null;
        }

        byte[] data = Hex.decodeHex(hexData.substring(2, hexData.length() - 1).toCharArray());

        return decodeAvatar(data, width, height);
    } else {

        cursor.close();
        return null;
    }
}

From source file:net.ccghe.emocha.model.DBAdapter.java

private static String getFirst(String column, String filter, String table, int columnId) {
    String result = null;/*w w  w  .  j  av  a2 s .c  o m*/
    Cursor c = sDB.query(table, new String[] { column }, filter, null, null, null, null);
    if (c.getCount() > 0) {
        c.moveToFirst();
        result = c.getString(columnId);
    }
    c.close();
    return result;
}