List of usage examples for android.database Cursor close
void close();
From source file:Main.java
public static void addToMediaStorePlaylist(ContentResolver resolver, int audioId, long playlistId) { String[] cols = new String[] { "count(*)" }; Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId); Cursor cur = resolver.query(uri, cols, null, null, null); cur.moveToFirst();//from w w w. jav a2 s . c om final int base = cur.getInt(0); cur.close(); ContentValues values = new ContentValues(); values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId)); values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId); resolver.insert(uri, values); }
From source file:Main.java
public static int getApnPortInt(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();/*from w ww.ja va 2s . c o m*/ if (c.isAfterLast()) { c.close(); return -1; } int result = c.getInt(c.getColumnIndex(APN_PROP_PORT)); return result; }
From source file:Main.java
public static String getApnProxy(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();//from w ww . j av a 2s. c om if (c.isAfterLast()) { c.close(); return null; } String strResult = c.getString(c.getColumnIndex(APN_PROP_PROXY)); c.close(); return strResult; }
From source file:Main.java
public static String getApn(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();// ww w . ja v a2 s.c om if (c.isAfterLast()) { c.close(); return null; } String strResult = c.getString(c.getColumnIndex(APN_PROP_APN)); c.close(); return strResult; }
From source file:Main.java
public static String getApnPort(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();// w w w.j a va 2s. c om if (c.isAfterLast()) { c.close(); return "80"; } String port = null; port = c.getString(c.getColumnIndex(APN_PROP_PORT)); if (port == null) { c.close(); port = "80"; } c.close(); return port; }
From source file:fr.itinerennes.utils.IOUtils.java
/** * Closes an InputStream.// w w w. j a va 2 s. co m * <p> * Equivalent to {@link Cursor#close()} but accept null values. * * @param cursor * the {@link Cursor} to close, may be null or already closed */ public static void close(final Cursor cursor) { if (null != cursor && !cursor.isClosed()) { cursor.close(); } }
From source file:Main.java
public static boolean hasShortcut(Context cx) { boolean result = false; String title = null;//from w w w . ja v a 2s .com try { final PackageManager pm = cx.getPackageManager(); title = pm.getApplicationLabel(pm.getApplicationInfo(cx.getPackageName(), PackageManager.GET_META_DATA)) .toString(); } catch (Exception e) { e.printStackTrace(); } final String AUTHORITY; if (android.os.Build.VERSION.SDK_INT < 8) { AUTHORITY = "com.android.launcher.settings"; } else { AUTHORITY = "com.android.launcher2.settings"; } final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true"); final Cursor c = cx.getContentResolver().query(CONTENT_URI, null, "title=?", new String[] { title }, null); if (c != null && c.moveToFirst()) { c.close(); result = true; } return result; }
From source file:Main.java
public static void logTableDump(SQLiteDatabase db, String tablename) { Cursor cursor = db.query(tablename, null, null, null, null, null, null); try {//from w w w . ja v a 2 s .c o m String dump = DatabaseUtils.dumpCursorToString(cursor); } finally { cursor.close(); } }
From source file:Main.java
/** Returns true if there in the supplied database exists a row in the table 'tableName' where 'columnName'='columnValueWanted'. * * @param db A readable SQLiteDatabase object. * @param tableName The name of the table to scan. "FROM tableName" * @param columnName The name of the column * @param columnValueWanted The values you want to see if exists in a column. * @return Does the wanted value exist in the column in any row of the table in the database? *//* ww w.ja v a 2 s .c om*/ public static boolean containsRowWithWhereStatement(SQLiteDatabase db, String tableName, String columnName, String columnValueWanted) { Cursor c = db.query(tableName, new String[] { columnName }, columnName + "=?", new String[] { columnValueWanted }, null, null, null, "1"); boolean output = c.getCount() > 0; c.close(); return output; }
From source file:Main.java
/** * Check if we have the schema information for a model in our database * @param model the model we want to check * @param db a readable link to our database * @return if the model schema exists/*from w w w. j av a2s . c om*/ */ public static synchronized boolean schemaCheck(SQLiteDatabase db, String model) { Cursor cursor = db.rawQuery("select DISTINCT tbl_name from sqlite_master where tbl_name = '" + model + "'", null); if (cursor != null) { if (cursor.getCount() > 0) { cursor.close(); return true; } cursor.close(); } return false; }