List of usage examples for android.database Cursor close
void close();
From source file:Main.java
@SuppressLint("NewApi") public static String getRealPathFromURI_API19(Context context, Uri uri) { String filePath = ""; if (DocumentsContract.isDocumentUri(context, uri)) { String wholeID = DocumentsContract.getDocumentId(uri); // Split at colon, use second item in the array String[] splits = wholeID.split(":"); if (splits.length == 2) { String id = splits[1]; String[] column = { MediaStore.Images.Media.DATA }; // where id is equal to String sel = MediaStore.Images.Media._ID + "=?"; Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[] { id }, null); int columnIndex = cursor.getColumnIndex(column[0]); if (cursor.moveToFirst()) { filePath = cursor.getString(columnIndex); }// w w w . ja v a 2 s .co m cursor.close(); } } else { filePath = uri.getPath(); } return filePath; }
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)); }/*from www . j av a2 s . c om*/ } if (cursor != null && !cursor.isClosed()) { cursor.close(); } return areaMap; }
From source file:Main.java
public static boolean isMediaScannerScanning(Context context) { boolean result = false; Cursor cursor = query(context, MediaStore.getMediaScannerUri(), new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null); if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst();/* w w w .java 2 s . com*/ result = "external".equals(cursor.getString(0)); } cursor.close(); } return result; }
From source file:Main.java
public static String get(Context context, String key) { String temp = null;/*from ww w. j av a2s. c om*/ 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
private static String getRealPathFromURI(Context context, Uri contentURI) { String result;/*w w w . j ava 2 s.c o m*/ Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { // Source is Dropbox or other similar local file path result = contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; }
From source file:co.rewen.statex.AsyncLocalStorageUtil.java
/** * Returns the value of the given key, or null if not found. *//* w ww .j ava2 s . c o m*/ /* package */ static @Nullable String getItemImpl(SQLiteDatabase db, String key) { String[] columns = { VALUE_COLUMN }; String[] selectionArgs = { key }; Cursor cursor = db.query(TABLE_STATE, columns, KEY_COLUMN + "=?", selectionArgs, null, null, null); try { if (!cursor.moveToFirst()) { return null; } else { return cursor.getString(0); } } finally { cursor.close(); } }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static Cursor queryAccountsForProvider(ContentResolver cr, String[] projection, long providerId) { StringBuilder where = new StringBuilder(Imps.Account.ACTIVE); where.append("=1 AND ").append(Imps.Account.PROVIDER).append('=').append(providerId); Cursor c = cr.query(Imps.Account.CONTENT_URI, projection, where.toString(), null, null); if (c != null && !c.moveToFirst()) { c.close(); return null; }/*from w w w . j a v a 2s . c om*/ return c; }
From source file:Main.java
public static List<String> GetColumns(SQLiteDatabase db, String tableName) { List<String> ar = null; Cursor c = null; try {/*from ww w .ja v a 2 s. c o m*/ c = db.rawQuery("select * from " + tableName + " limit 1", null); if (c != null) { ar = new ArrayList<String>(Arrays.asList(c.getColumnNames())); } } catch (Exception e) { Log.v(tableName, e.getMessage(), e); e.printStackTrace(); } finally { if (c != null) c.close(); } return ar; }
From source file:free.yhc.netmbuddy.share.Json.java
static JSONObject videoToJson(long vid) { final int COLI_VIDEOID = 0; final int COLI_TITLE = 1; final int COLI_AUTHOR = 2; final int COLI_VOLUME = 3; final int COLI_PLAYTIME = 4; final int COLI_BOOKMARKS = 5; Cursor c = DB.get().queryVideo(vid, new ColVideo[] { ColVideo.VIDEOID, ColVideo.TITLE, ColVideo.AUTHOR, ColVideo.VOLUME, ColVideo.PLAYTIME, ColVideo.BOOKMARKS }); if (!c.moveToFirst()) { c.close(); return null; }//from w w w .j a v a2 s .c om JSONObject jo = new JSONObject(); try { jo.put(FYTID, c.getString(COLI_VIDEOID)); jo.put(FTITLE, c.getString(COLI_TITLE)); // NOTE // Below field - author - is newly added at Database version 2 // So, we cannot sure that DB includes valid field value for them. if (Utils.isValidValue(c.getString(COLI_AUTHOR))) jo.put(FAUTHOR, c.getString(COLI_AUTHOR)); jo.put(FPLAYTIME, c.getInt(COLI_PLAYTIME)); jo.put(FBOOKMARKS, c.getString(COLI_BOOKMARKS)); int vol = c.getInt(COLI_VOLUME); if (Policy.DEFAULT_VIDEO_VOLUME != vol) jo.put(FVOLUME, vol); } catch (JSONException e) { jo = null; } c.close(); return jo; }
From source file:Main.java
private static int getImageRotationAngle(Uri imageUri, ContentResolver contentResolver) throws IOException { int angle = 0; Cursor cursor = contentResolver.query(imageUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);//from ww w . j av a 2s . c o m if (cursor != null) { if (cursor.getCount() == 1) { cursor.moveToFirst(); angle = cursor.getInt(0); } cursor.close(); } else { ExifInterface exif = new ExifInterface(imageUri.getPath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: angle = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: angle = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: angle = 90; break; default: break; } } return angle; }