List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {/*from w ww . j a v a2 s. co 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); } } catch (Exception e) { // FileLog.e("tmessages", e); } finally { if (cursor != null) { cursor.close(); } } return null; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {//from w w w . j a v a 2 s . co 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); } } catch (Exception e) { Log.e("tmessages", e.getMessage()); } finally { if (cursor != null) { cursor.close(); } } return null; }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {//w w w.ja v a 2 s. com cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int column_index = cursor.getColumnIndexOrThrow(column); String value = cursor.getString(column_index); if (value.startsWith("content://") || !value.startsWith("/") && !value.startsWith("file://")) { return null; } return value; } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } return null; }
From source file:com.nextgis.mobile.map.Layer.java
protected static String getFileNameByUri(final Context context, Uri uri, String defaultName) { String fileName = defaultName; Uri filePathUri = uri;/*from ww w . ja v a 2 s . co m*/ try { if (uri.getScheme().toString().compareTo("content") == 0) { Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndex(MediaStore.Images.Media.DATA); //Instead of "MediaStore.Images.Media.DATA" can be used "_data" filePathUri = Uri.parse(cursor.getString(column_index)); fileName = filePathUri.getLastPathSegment().toString(); } } else if (uri.getScheme().compareTo("file") == 0) { fileName = filePathUri.getLastPathSegment().toString(); } else { fileName = fileName + "_" + filePathUri.getLastPathSegment(); } } catch (Exception e) { //do nothing, only return default file name; Log.d(TAG, e.getLocalizedMessage()); } return fileName; }
From source file:Main.java
public static int getOrientation(Context context, Uri photoUri, File file) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null && cursor.getCount() != 1) { cursor.moveToFirst(); return cursor.getInt(0); }//from ww w.ja v a 2 s. c o m int rotate = 0; ExifInterface exif = null; try { exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_NORMAL: rotate = 0; break; } return rotate; }
From source file:ca.mudar.parkcatcher.utils.ParserUtils.java
/** * Query and return the {@link SyncColumns#UPDATED} time for the requested * {@link Uri}. Expects the {@link Uri} to reference a single item. *///from www.j a va 2 s.c o m public static long queryItemUpdated(Uri uri, ContentResolver resolver) { final String[] projection = { SyncColumns.UPDATED }; final Cursor cursor = resolver.query(uri, projection, null, null, null); try { if (cursor.moveToFirst()) { return cursor.getLong(0); } else { return ParkingContract.UPDATED_NEVER; } } finally { cursor.close(); } }
From source file:Main.java
protected static long findThreadId(Context context, String messageId) { StringBuilder sb = new StringBuilder('('); sb.append(Telephony.Mms.MESSAGE_ID); sb.append('='); sb.append(DatabaseUtils.sqlEscapeString(messageId)); sb.append(" AND "); sb.append(Telephony.Mms.MESSAGE_TYPE); sb.append('='); sb.append(MESSAGE_TYPE_SEND_REQ);//from w w w . j ava2 s . c o m // TODO ContentResolver.query() appends closing ')' to the selection argument // sb.append(')'); Cursor cursor = context.getContentResolver().query(Telephony.Mms.CONTENT_URI, new String[] { Telephony.Mms.THREAD_ID }, sb.toString(), null, null); if (cursor != null) { try { if ((cursor.getCount() == 1) && cursor.moveToFirst()) { return cursor.getLong(0); } } finally { cursor.close(); } } return -1; }
From source file:fr.mixit.android.utils.SyncUtils.java
public static String getLocalMd5(ContentResolver resolver, String url) { final String syncId = MixItContract.Sync.generateSyncId(url); final Uri uri = MixItContract.Sync.buildSyncUri(syncId); Cursor cursor = resolver.query(uri, SyncQuery.PROJECTION, null, null, null); try {//from w ww . ja v a 2s .c om if (!cursor.moveToFirst()) return ""; return cursor.getString(SyncQuery.MD5); } finally { cursor.close(); } }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentUri) { Cursor cursor = null; try {//from w w w. j av a 2 s . com String[] proj = { MediaStore.Images.Media.DATA }; cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } finally { if (cursor != null) { cursor.close(); } } }
From source file:Main.java
public static int getOrientation(Context context, Uri bitmapUri) { Cursor cursor = context.getContentResolver().query(bitmapUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor == null || cursor.getCount() != 1) { return -1; }//from ww w . j av a 2 s. c o m cursor.moveToFirst(); return cursor.getInt(0); }