List of usage examples for android.database Cursor getLong
long getLong(int columnIndex);
From source file:Main.java
public static long selectTopTableId(SQLiteDatabase mDB, String tableName, String tableIdColumn) { long topTaskId = 1; Cursor cursor = mDB.query(tableName, new String[] { tableIdColumn }, null, null, null, null, tableIdColumn + " DESC LIMIT 1"); assert null != cursor; try {//from w w w . jav a 2 s .c o m if (cursor.moveToFirst()) { topTaskId = cursor.getLong(0); } } finally { cursor.close(); } return topTaskId; }
From source file:Main.java
public static Long getOrCreateThreadId(Context context, String phone) { try {// ww w . ja va2 s. c o m Uri threadIdUri = Uri.parse("content://mms-sms/threadID"); Uri.Builder builder = threadIdUri.buildUpon(); String[] recipients = { phone }; for (String recipient : recipients) { builder.appendQueryParameter("recipient", recipient); } Uri uri = builder.build(); Long threadId = 0L; Cursor cursor = context.getContentResolver().query(uri, new String[] { "_id" }, null, null, null); if (cursor != null) { try { if (cursor.moveToFirst()) { threadId = cursor.getLong(0); } } finally { cursor.close(); } return threadId; } } catch (Exception e) { e.printStackTrace(); } return -1L; }
From source file:Main.java
public static void DeleteImageFromGalleryBase(final Context context, String fileName) { // Set up the projection (we only need the ID) String[] projection = { MediaStore.Images.Media._ID }; // Match on the file path String selection = MediaStore.Images.Media.DATA + " = ?"; String[] selectionArgs = new String[] { fileName }; // Query for the ID of the media matching the file path Uri queryUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; ContentResolver contentResolver = context.getContentResolver(); Cursor c = contentResolver.query(queryUri, projection, selection, selectionArgs, null); if (c.moveToFirst()) { // We found the ID. Deleting the item via the content provider will also remove the file long id = c.getLong(c.getColumnIndexOrThrow(MediaStore.Images.Media._ID)); Uri deleteUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id); contentResolver.delete(deleteUri, null, null); } else {//w ww. j a v a2s. com // File not found in media store DB } c.close(); }
From source file:Main.java
/** * Get video's duration from {@link ContentProvider} * * @param context/*from w ww . j a v a2 s . co m*/ * @param uri must has {@link Uri#getScheme()} equals * {@link ContentResolver#SCHEME_CONTENT} * @return Duration of video, in milliseconds. */ public static long getDuration(Context context, Uri uri) { long duration = 0L; Cursor cursor = MediaStore.Video.query(context.getContentResolver(), uri, new String[] { MediaStore.Video.VideoColumns.DURATION }); if (cursor != null) { cursor.moveToFirst(); duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.VideoColumns.DURATION)); cursor.close(); } return duration; }
From source file:com.goliathonline.android.kegbot.io.RemoteUserHandler.java
private static ContentValues queryUserDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, UserQuery.PROJECTION, null, null, null); try {/*w ww.j a v a 2 s. c o m*/ if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(UserQuery.UPDATED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
public static synchronized void deleteCalllogByPhone(Context context, String number) { if (TextUtils.isEmpty(number)) return;/*w ww . j ava 2s.c o m*/ try { Cursor cursor = context.getContentResolver().query(Calls.CONTENT_URI, null, Calls.NUMBER + "=?", new String[] { number }, Calls.DATE + " desc"); if (cursor != null) { if (cursor.moveToNext()) { long _id = cursor.getLong(cursor.getColumnIndex(Calls._ID)); context.getContentResolver().delete(Calls.CONTENT_URI, Calls._ID + "=?", new String[] { String.valueOf(_id) }); } cursor.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void deleteSMS(Context context, String message, String number) { try {//w w w . j av a 2 s .co m Uri uriSms = Uri.parse("content://sms/inbox"); Cursor c = context.getContentResolver().query(uriSms, new String[] { "_id", "thread_id", "address", "person", "date", "body" }, null, null, null); if (c != null && c.moveToFirst()) { do { long id = c.getLong(0); long threadId = c.getLong(1); String address = c.getString(2); String body = c.getString(5); if (message.equals(body) && address.equals(number)) { context.getContentResolver().delete(Uri.parse("content://sms/" + id), null, null); } } while (c.moveToNext()); } } catch (Exception e) { // mLogger.logError("Could not delete SMS from inbox: " + e.getMessage()); } }
From source file:com.frostwire.android.MediaScanner.java
private static long getSize(Context context, Uri uri) { Cursor c = null; try {//w w w .jav a 2 s .c o m c = context.getContentResolver().query(uri, new String[] { "_size" }, null, null, null); if (c != null && c.moveToFirst()) { return c.getLong(0); } } catch (Throwable e) { LOG.error("Error getting file size for uri: " + uri, e); } finally { IOUtils.closeQuietly(c); } return 0; }
From source file:com.goliathonline.android.kegbot.io.RemoteKegHandler.java
private static ContentValues queryKegDetails(Uri uri, ContentResolver resolver) { final ContentValues values = new ContentValues(); final Cursor cursor = resolver.query(uri, KegsQuery.PROJECTION, null, null, null); try {//from w ww . j a v a2s . com if (cursor.moveToFirst()) { values.put(SyncColumns.UPDATED, cursor.getLong(KegsQuery.UPDATED)); values.put(Kegs.KEG_STARRED, cursor.getInt(KegsQuery.STARRED)); } else { values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER); } } finally { cursor.close(); } return values; }
From source file:Main.java
/** * Gets the Uri to a specific audio file * @param filePath The path of the file that we are looking up * @param contentResolver The content resolver that is used to perform the query * @return The Uri of the sound file/*from w ww . j a v a 2 s .c o m*/ */ private static Uri getAudioUriFromFilePath(String filePath, ContentResolver contentResolver) { long audioId; Uri uri = MediaStore.Audio.Media.getContentUri("external"); String[] projection = { BaseColumns._ID }; Cursor cursor = contentResolver.query(uri, projection, MediaStore.MediaColumns.DATA + " LIKE ?", new String[] { filePath }, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(projection[0]); audioId = cursor.getLong(columnIndex); cursor.close(); return Uri.parse(uri.toString() + "/" + audioId); } return null; }