List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:Main.java
public static String getPath(Context context, Uri uri) throws NullPointerException { final String[] projection = { MediaColumns.DATA }; final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); final int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
From source file:Main.java
public static int getSmsCount(Context context) { try {// w w w .j a va 2 s .c o m int result = 0; Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"), new String[] { "count(_id)", }, null, null, null); if (c.moveToFirst()) { result = c.getInt(0); } c.close(); return result; } catch (Throwable t) { LOGE("getSmsCount: " + t.getMessage()); t.printStackTrace(); } return 0; }
From source file:Main.java
/** * Get path of image from uri/*from w ww . j a va2s . c o m*/ * * @param contentResolver * @param contentURI * @return path of image. Null if not found. */ public static String getRealImagePathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Images.ImageColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
public static String getAbsolutePathFromUri(Context ctx, Uri contentUri) { String[] proj = { MediaStore.Video.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
From source file:Main.java
static String getAccessTokenFromTable(Context context, String tableName) { String token = null;//from www . j a va 2 s. c o m try { SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null); Cursor c = db.rawQuery( "SELECT " + DEPRECATED_ACCESS_TOKEN_COLUMN + " FROM " + tableName + " WHERE local_id=0", null); if (c.moveToFirst() && c.getColumnIndex(DEPRECATED_ACCESS_TOKEN_COLUMN) != -1) { token = c.getString(c.getColumnIndex(DEPRECATED_ACCESS_TOKEN_COLUMN)); } c.close(); db.close(); } catch (SQLException e) { // DB doesn't exist } return token; }
From source file:Main.java
/** * Get path of video from uri/*from ww w . j av a2 s . c o m*/ * * @param contentResolver * @param contentURI * @return path of video. Null if not found. */ public static String getRealVideoPathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Video.VideoColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
/** * @param mContext//from w w w . j a v a2s . com * @param number * @return sunrise.l String 2012-5-28 */ public static String getNameFormNumber(Context mContext, String number) { String name = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, number); Cursor cur = mContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cur != null && cur.moveToFirst()) { int nameIndex = cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME); name = cur.getString(nameIndex); } cur.close(); return name; }
From source file:Main.java
public static String get(Context context, String key) { String temp = null;/* w w w . j a va2 s . c o m*/ Cursor cur = null; try { cur = context.getContentResolver().query(CONTENT_URI, null, "key='" + key + "'", null, null); if (null != cur && cur.moveToFirst()) temp = cur.getString(1); } catch (Exception e) { Log.e("AspShareUtil", "Error while get", e); } finally { if (cur != null) cur.close(); } return temp; }
From source file:Main.java
public static int getRotationFromGallery(Context context, Uri imageUri) { String[] columns = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = context.getContentResolver().query(imageUri, columns, null, null, null); if (cursor == null) return 0; cursor.moveToFirst(); int orientationColumnIndex = cursor.getColumnIndex(columns[0]); return cursor.getInt(orientationColumnIndex); }
From source file:Main.java
public static int getImageIdFromPath(Activity activity, String filePath) { String[] projection = { MediaStore.Images.Media._ID }; Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; String where = String.format("_data like '%s' ", filePath); Cursor cursor = MediaStore.Images.Media.query(activity.getContentResolver(), uri, projection, where, null); int image_id = 0; if (cursor.getCount() != 0) { cursor.moveToFirst(); image_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); cursor.close();//from w w w . j a v a 2s . c om } return image_id; }