List of usage examples for android.database Cursor close
void close();
From source file:Main.java
public static String uriToString(Context context, Uri uri) { String scheme = uri.getScheme(); if (scheme != null) { if (scheme.equals("http") || scheme.equals("https")) { return uri.toString(); } else if (scheme.equals("content") || scheme.equals("file")) { Cursor cursor = context.getContentResolver().query(uri, new String[] { OpenableColumns.DISPLAY_NAME }, null, null, null); if (cursor.moveToNext()) { String name = cursor.getString(0); cursor.close(); return name; }// w ww.j a va2s.c om cursor.close(); return uri.getPath(); } } return uri.toString(); }
From source file:Main.java
public static String getSmsText(Context context, String msgId) { String result = null;/* ww w.j av a 2s . co m*/ try { Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"), new String[] { "body", }, "_id = ?", new String[] { msgId, }, null); if (c.moveToFirst()) { result = c.getString(0); } c.close(); } catch (Throwable t) { LOGE("getSmsText: " + t.getMessage()); t.printStackTrace(); result = null; } return result; }
From source file:Main.java
public static ArrayList<String> getColumns(ContentResolver resolver, String uri, String[] projectionArray) { //String returnValue = ""; ArrayList<String> columns = new ArrayList<String>(); try {//from w ww. j a va2s .c o m //Issue query Cursor c = resolver.query(Uri.parse(uri), projectionArray, null, null, null); //Get all column names and display if (c != null) { String[] colNames = c.getColumnNames(); //Close the cursor c.close(); //String columnNamesOutput = ""; for (int k = 0; k < colNames.length; k++) columns.add(colNames[k]); } } catch (Throwable t) { } return columns; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentURI) { String result = null;/* ww w. j av a 2 s . c om*/ Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; }
From source file:Main.java
public static int getChannelCount(ContentResolver resolver, String inputId) { Uri uri = TvContract.buildChannelsUriForInput(inputId); String[] projection = { TvContract.Channels._ID }; Cursor cursor = null; try {// ww w .ja v a 2 s.c o m cursor = resolver.query(uri, projection, null, null, null); if (cursor != null) { return cursor.getCount(); } } finally { if (cursor != null) { cursor.close(); } } return 0; }
From source file:Main.java
/** * Get specific row values from the database, * e.g. all years stored in the database or * all months of a year stored in the database or * all days in a month of a year stored in the database * * @param db/*from w ww. j ava 2 s . c om*/ * pointer to database * @param requestField * requested row from db * "year" returns all year values found * "month" returns all month values found in year <code>requestLimiterYear</code> * "day" returns all day values found in month <code>requestLimiterMonth</code> * and year <code>requestLimiterYear</code> * @param requestLimiterMonth * limiter for request * unused if requestField is "year" * unused if requestField is "month" * month if requestField is "day" * @param requestLimiterYear * limiter for request * unused if requestField is "year" * year if requestField is "month" * year if requestField is "day" * * @return <code>ArrayList<Integer></code> * array list with all entries found */ public static ArrayList<Integer> getEntries(SQLiteDatabase db, String requestField, int requestLimiterMonth, int requestLimiterYear) { /** Array list holding the found values */ ArrayList<Integer> returnArray = new ArrayList<>(); /** Limiter for row search */ String queryRequest = "select distinct " + requestField + " from " + TABLE_NAME; if (requestField.equalsIgnoreCase("day")) { queryRequest += " where month = " + String.valueOf(requestLimiterMonth) + " and year = " + String.valueOf(requestLimiterYear); } else if (requestField.equalsIgnoreCase("month")) { queryRequest += " where year = " + String.valueOf(requestLimiterYear); } /** Cursor holding the records of a day */ Cursor allRows = db.rawQuery(queryRequest, null); allRows.moveToFirst(); for (int i = 0; i < allRows.getCount(); i++) { returnArray.add(allRows.getInt(0)); allRows.moveToNext(); } allRows.close(); return returnArray; }
From source file:Main.java
public static String getGSFID(Context context) { String result;//from w w w . j av a 2s. c om final Uri URI = Uri.parse("content://com.google.android.gsf.gservices"); final String ID_KEY = "android_id"; String[] params = { ID_KEY }; Cursor c = context.getContentResolver().query(URI, null, null, params, null); if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) { return null; } else { result = Long.toHexString(Long.parseLong(c.getString(1))); } c.close(); return result; }
From source file:fr.mixit.android.io.JSONHandler.java
protected static boolean isRowExisting(Uri uri, String[] projection, ContentResolver resolver) { final Cursor cursor = resolver.query(uri, projection, null, null, null); try {//from w w w . j a v a 2 s. com if (!cursor.moveToFirst()) return false; } finally { cursor.close(); } return true; }
From source file:Main.java
public static boolean isExistShortcut(Activity context, String authorities) { boolean isInstallShortcut = false; final ContentResolver cr = context.getContentResolver(); final Uri CONTENT_URI = Uri.parse("content://" + authorities + "/favorites?notify=true"); Cursor c = cr.query(CONTENT_URI, new String[] { "iconPackage" }, "iconPackage=?", new String[] { context.getApplication().getPackageName() }, null); if (c != null) { if (c.getCount() > 0) { isInstallShortcut = true;//from w ww . j av a 2 s.c om } c.close(); } return isInstallShortcut; }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentUri) { String res = null;//from w w w. j a v a 2s . c om String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); if (cursor.moveToFirst()) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); res = cursor.getString(column_index); } cursor.close(); return res; }