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:Main.java

public static Map<String, Integer> getProvince(SQLiteDatabase db, String tableName) {
    Map<String, Integer> provinceMap = new LinkedHashMap<String, Integer>();
    Cursor cursor = db.query(tableName, new String[] { "DQX_DQXX01", "DQXX02" }, "DQXX03=?",
            new String[] { "1" }, null, null, "DQX_DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            provinceMap.put(cursor.getString(1), cursor.getInt(0));
        }//from ww w . j  ava 2  s  .co m
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return provinceMap;
}

From source file:Main.java

public static Map<String, Integer> getArea(SQLiteDatabase db, String tableName, int dqx_dqxx01) {
    Map<String, Integer> areaMap = new LinkedHashMap<String, Integer>();
    Cursor cursor = db.query(tableName, new String[] { "DQXX02", "DQXX01" }, "DQX_DQXX01=?",
            new String[] { "" + dqx_dqxx01 }, null, null, "DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            areaMap.put(cursor.getString(0), cursor.getInt(1));
        }/*  w w w.  java  2s  .  c om*/
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return areaMap;
}

From source file:com.radadev.xkcd.Comics.java

public static void downloadComic(Integer comicNumber, Context context)
        throws FileNotFoundException, IOException {
    ComicDbAdapter dbAdapter = new ComicDbAdapter(context);
    dbAdapter.open();//from  w  ww. j  a v  a2 s.  c o  m
    try {
        dbAdapter.updateComic(comicNumber);
        File file = new File(getSdDir(context), comicNumber.toString() + ".png");
        if (file.length() <= 0) {
            Cursor cursor = dbAdapter.fetchComic(comicNumber);
            String url = cursor.getString(cursor.getColumnIndexOrThrow(Comics.SQL_KEY_IMAGE));

            if (url == null || url.length() == 0) {
                dbAdapter.updateComic(comicNumber);
                cursor.close();
                cursor = dbAdapter.fetchComic(comicNumber);
                url = cursor.getString(cursor.getColumnIndexOrThrow(Comics.SQL_KEY_IMAGE));
            }
            cursor.close();

            Bitmap bitmap = Comics.downloadBitmap(url);
            FileOutputStream fileStream = new FileOutputStream(file);
            bitmap.compress(CompressFormat.PNG, 100, fileStream);
            bitmap.recycle();
            fileStream.close();
        }
    } finally {
        dbAdapter.close();
    }
}

From source file:Main.java

public static String getLatestCameraPicture(Context context) {

    if (!existSDCard()) {
        return null;
    }/*from  w  w  w  .  ja va 2 s  .com*/

    String[] projection = new String[] { MediaStore.Images.ImageColumns._ID,
            MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
            MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE };
    Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
            null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
    if (cursor.moveToFirst()) {
        String path = cursor.getString(1);
        return path;
    }
    return null;
}

From source file:Main.java

private static String getCoverPath(Context context, long albumId) {
    String path = null;/*from ww  w. j  a v a  2s. co  m*/
    Cursor cursor = context.getContentResolver().query(
            Uri.parse("content://media/external/audio/albums/" + albumId), new String[] { "album_art" }, null,
            null, null);
    if (cursor != null) {
        cursor.moveToNext();
        path = cursor.getString(0);
        cursor.close();
    }
    return path;
}

From source file:Main.java

public static String getPathFromUri(Context context, Uri u) {
    String[] pojo = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(u, pojo, null, null, null);
    String picPath = null;/*from   w  w  w  .j a v  a  2  s  .  c  o  m*/
    if (cursor != null) {
        int columnIndex = cursor.getColumnIndexOrThrow(pojo[0]);
        cursor.moveToFirst();
        picPath = cursor.getString(columnIndex);
        return picPath;
    }
    return null;
}

From source file:Main.java

/**
 * Finding contact name by telephone number.
 *
 * @param context Context/*from  w  w  w  . j a va  2s .  c om*/
 * @param number  Telephone number
 * @return Contact display name
 */
public static String getContactName(Context context, String number) {
    Log.d(TAG, "Searching contact with number: " + number);

    /* define the columns I want the query to return */
    String[] projection = new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME };

    /* encode the phone number and build the filter URI */
    Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    /* query time */
    Log.d(TAG, "Sending query");
    Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);

    String name = null;
    if (cursor.moveToFirst()) {
        /* Get values from contacts database: */
        name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
        Log.d(TAG, "Contact found for number: " + number + ". The name is: " + name);
    } else {
        Log.d(TAG, "Contact not found for number: " + number);
    }

    return name;
}

From source file:Main.java

public static String geVideotName(Activity activity, Uri uri) throws Exception {

    String[] projection = { MediaStore.Video.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    activity.startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();//from w w w . j  av a  2  s .c  om
    Uri filePathUri = Uri.parse(cursor.getString(column_index));
    String file_name = filePathUri.getLastPathSegment().toString();
    return file_name;
}

From source file:Main.java

public static String getName(Activity activity, Uri uri) {

    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    activity.startManagingCursor(cursor);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();//from   ww  w  .  j  av  a  2 s . c o m
    Uri filePathUri = Uri.parse(cursor.getString(column_index));
    String file_name = filePathUri.getLastPathSegment().toString();
    return file_name;
}

From source file:Main.java

public static File parseFileByIntentData(Context context, Intent data) {
    File file = null;//from   ww w  .ja  v  a 2 s.c om
    if (data != null && data.getData() != null) {
        String[] proj = { MediaStore.Images.Media.DATA };
        CursorLoader cursorLoader = new CursorLoader(context, data.getData(), proj, null, null, null);
        Cursor cursor = null;
        try {
            cursor = cursorLoader.loadInBackground();
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            file = new File(cursor.getString(column_index));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    return file;
}