List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:net.sf.sprockets.database.Cursors.java
/** * Get the int value in the first row and column. * * @param close true to close the cursor or false to leave it open * @return {@link Integer#MIN_VALUE} if the cursor is empty * @since 2.5.0//www. ja v a 2 s . com */ public static int firstInt(Cursor cursor, boolean close) { int i = cursor.moveToFirst() ? cursor.getInt(0) : Integer.MIN_VALUE; close(cursor, close); return i; }
From source file:Main.java
/** * Get Image orientation from uri//from w w w . jav a2s . co m * * @param context Context of image * @param photoUri Uri of image * @return */ public static int getOrientation(Context context, Uri photoUri) { Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); try { if (cursor.moveToFirst()) { if (cursor.getInt(0) == ORIENTATION_270) return ExifInterface.ORIENTATION_ROTATE_270; else if (cursor.getInt(0) == ORIENTATION_180) return ExifInterface.ORIENTATION_ROTATE_180; else if (cursor.getInt(0) == ORIENTATION_90) return ExifInterface.ORIENTATION_ROTATE_90; } } finally { cursor.close(); } return -1; }
From source file:Main.java
public static Uri pathToContentUri(Context context, String imagePath) { Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { "_id" }, "_data=? ", new String[] { imagePath }, null); if (cursor != null && cursor.moveToFirst()) { int imageFile1 = cursor.getInt(cursor.getColumnIndex("_id")); Uri values1 = Uri.parse("content://media/external/images/media"); return Uri.withAppendedPath(values1, "" + imageFile1); } else {/*from www . j a v a2 s .co m*/ File imageFile = new File(imagePath); if (imageFile.exists()) { ContentValues values = new ContentValues(); values.put("_data", imagePath); Uri baseUri = Media.EXTERNAL_CONTENT_URI; return context.getContentResolver().insert(baseUri, values); } else { return null; } } }
From source file:Main.java
public static Uri getBitmapFromImageId(Activity activity, int imageId) { String[] tinyImgPprojection = { MediaStore.Images.Thumbnails._ID }; Cursor tinyCursor = Thumbnails.queryMiniThumbnail(activity.getContentResolver(), imageId, Thumbnails.MINI_KIND, tinyImgPprojection); if (tinyCursor.getCount() != 0) { tinyCursor.moveToFirst();// www. j av a 2s. com int tinyImgId = tinyCursor.getInt(tinyCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID)); tinyCursor.close(); return Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, String.valueOf(tinyImgId)); } else { tinyCursor.close(); return null; } }
From source file:Main.java
public static int getLastImageId(Context context) { final String[] imageColumns = { Images.Media._ID }; final String imageOrderBy = Images.Media._ID + " DESC"; Cursor cursor = context.getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);// w w w .j a v a 2 s . c om if (cursor == null) return 0; int id = 0; if (cursor.moveToFirst()) { id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID)); } cursor.close(); return id; }
From source file:Main.java
public static int getOrientation(Context context, Uri photoUri) { /* it's on the external media. */ Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor.getCount() != 1) { return -1; }/* w w w. j av a 2s. co m*/ cursor.moveToFirst(); return cursor.getInt(0); }
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)); }// w w w . j av a 2 s . c o m } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return provinceMap; }
From source file:Main.java
public static Uri getAudioContentUri(Context context, File file) { String filePath = file.getAbsolutePath(); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media._ID }, MediaStore.Audio.Media.DATA + "=?", new String[] { filePath }, null); cursor.moveToFirst();//from w w w . j av a 2 s . c om int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); Uri baseUri = Uri.parse("content://media/external/audio/media"); return Uri.withAppendedPath(baseUri, "" + id); }
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 ww . j av a 2 s. co m*/ } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return areaMap; }
From source file:Main.java
private static Set<Integer> getAllAvailableProtocolVersions(Context context) { ContentResolver contentResolver = context.getContentResolver(); Set<Integer> allAvailableVersions = new HashSet<Integer>(); Uri uri = Uri.parse("content://appsneva.facebook.orca.provider.MessengerPlatformProvider/versions"); String[] projection = new String[] { "version" }; Cursor c = contentResolver.query(uri, projection, null, null, null); if (c != null) { try {//from w ww. ja va 2 s. c o m int versionColumnIndex = c.getColumnIndex("version"); while (c.moveToNext()) { int version = c.getInt(versionColumnIndex); allAvailableVersions.add(version); } } finally { c.close(); } } return allAvailableVersions; }