List of usage examples for android.database Cursor getCount
int getCount();
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 ww . j a v a 2 s .com */ 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; }
From source file:Main.java
/** * Check if the database exist//w ww .jav a 2 s .c o m * * @return true if it exists, false if it doesn't */ public static boolean checkDataBase(Context context) { SQLiteDatabase checkDB = null; int count = 0; try { if (android.os.Build.VERSION.SDK_INT >= 17) { DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } checkDB = SQLiteDatabase.openDatabase(DB_PATH + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY); String selectRegistros = "SELECT COUNT(*) FROM Grupo_Gastos"; Cursor mCursor = checkDB.query(true, "Grupo_Gastos", new String[] { "_id" }, null, null, null, null, null, null); count = mCursor.getCount(); checkDB.close(); } catch (SQLiteException e) { // database doesn't exist yet. return false; } return count > 0; }
From source file:Main.java
public static boolean isExist(SQLiteDatabase db, String pageId, String lang) throws SQLException { boolean itemExist = false; Cursor c = db.query(TABLE_CONTENT_HELP, null, PAGE_ID + "=? AND " + PAGE_LANGUAGE + "=?", new String[] { pageId, lang }, null, null, null); if ((c != null) && (c.getCount() > 0)) { itemExist = true;/*from w ww .j a va2 s.c o m*/ } c.close(); return itemExist; }
From source file:Main.java
public static boolean checkShortCut(Context context, String appName) { boolean hasShortCut = false; try {/* w ww . j ava 2 s . c o m*/ ContentResolver cr = context.getContentResolver(); final String AUTHORITY1 = "com.android.launcher.settings"; final String AUTHORITY2 = "com.android.launcher2.settings"; String contentUri = ""; if (android.os.Build.VERSION.SDK_INT < 8) { contentUri = "content://" + AUTHORITY1 + "/favorites?notify=true"; } else { contentUri = "content://" + AUTHORITY2 + "/favorites?notify=true"; } final Uri CONTENT_URI = Uri.parse(contentUri); Cursor c = cr.query(CONTENT_URI, new String[] { "title", "iconResource" }, "title=?", new String[] { appName }, null); if (c != null && c.getCount() > 0) { hasShortCut = true; } } catch (Exception e) { } return hasShortCut; }
From source file:Main.java
/** * @param context The {@link Context} to use. * @param name The name of the new playlist. * @return A new playlist ID./*from www . j a va 2s . c o m*/ */ public static final long createPlaylist(final Context context, final String name) { if (name != null && name.length() > 0) { final ContentResolver resolver = context.getContentResolver(); final String[] projection = new String[] { PlaylistsColumns.NAME }; final String selection = PlaylistsColumns.NAME + " = '" + name + "'"; Cursor cursor = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, projection, selection, null, null); if (cursor.getCount() <= 0) { final ContentValues values = new ContentValues(1); values.put(PlaylistsColumns.NAME, name); final Uri uri = resolver.insert(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, values); return Long.parseLong(uri.getLastPathSegment()); } if (cursor != null) { cursor.close(); cursor = null; } return -1; } return -1; }
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 {//from w w w . ja v a 2s . com 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
public static String getLatestImage(Activity context) { String latestImage = null;//from w w w .j a va 2 s.c om String[] items = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }
From source file:Main.java
/** * Return the filename from a uri./* www. jav a 2 s . c o m*/ */ public static String getFilename(Context c, Uri uri) { try { String scheme = uri.getScheme(); if (scheme.equals("file")) { return uri.getLastPathSegment(); } else if (scheme.equals("content")) { String[] proj = { MediaStore.Files.FileColumns.DISPLAY_NAME }; Cursor cursor = c.getContentResolver().query(uri, proj, null, null, null); if (cursor != null && cursor.getCount() != 0) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME); cursor.moveToFirst(); return cursor.getString(columnIndex); } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int getOrientation(Context context, Uri photoUri) { int orientation = 0; Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null) { if (cursor.getCount() != 1) { return -1; }/*from w w w. jav a 2 s . c o m*/ cursor.moveToFirst(); orientation = cursor.getInt(0); cursor.close(); } return orientation; }
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;/*www.java 2 s .c o m*/ } c.close(); } return isInstallShortcut; }