android.provider.BaseColumns Java Examples
The following examples show how to use
android.provider.BaseColumns.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExplorerProvider.java From FireFiles with Apache License 2.0 | 6 votes |
private void createTablesV3(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_STORAGE + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + StorageColumns.NAME + " TEXT," + StorageColumns.TYPE + " TEXT," + StorageColumns.SCHEME + " TEXT," + StorageColumns.PATH + " TEXT," + StorageColumns.HOST + " TEXT," + StorageColumns.PORT + " INTEGER," + StorageColumns.USERNAME + " TEXT," + StorageColumns.PASSWORD + " TEXT," + StorageColumns.ANONYMOUS_LOGIN + " BOOLEAN," + "UNIQUE (" + StorageColumns.NAME + ", " + StorageColumns.HOST + ", " + StorageColumns.PATH + ") ON CONFLICT REPLACE " + ")"); }
Example #2
Source File: ContactsDatabase.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
public synchronized void removeDeletedRawContacts(@NonNull Account account) { Uri currentContactsUri = RawContacts.CONTENT_URI.buildUpon() .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name) .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type) .appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true") .build(); String[] projection = new String[] {BaseColumns._ID, RawContacts.SYNC1}; try (Cursor cursor = context.getContentResolver().query(currentContactsUri, projection, RawContacts.DELETED + " = ?", new String[] {"1"}, null)) { while (cursor != null && cursor.moveToNext()) { long rawContactId = cursor.getLong(0); Log.i(TAG, "Deleting raw contact: " + cursor.getString(1) + ", " + rawContactId); context.getContentResolver().delete(currentContactsUri, RawContacts._ID + " = ?", new String[] {String.valueOf(rawContactId)}); } } }
Example #3
Source File: TelephonyCompat.java From flutter_sms with MIT License | 6 votes |
/** * Given the recipients list and subject of an unsaved message, * return its thread ID. If the message starts a new thread, * allocate a new thread ID. Otherwise, use the appropriate * existing thread ID. * * <p>Find the thread ID of the same set of recipients (in any order, * without any additions). If one is found, return it. Otherwise, * return a unique thread ID.</p> */ private static long getOrCreateThreadIdInternal(Context context, Set<String> recipients) { Uri.Builder uriBuilder = THREAD_ID_CONTENT_URI.buildUpon(); for (String recipient : recipients) { uriBuilder.appendQueryParameter("recipient", recipient); } Uri uri = uriBuilder.build(); Cursor cursor = query( context.getContentResolver(), uri, new String[] {BaseColumns._ID}); if (cursor != null) { try { if (cursor.moveToFirst()) { return cursor.getLong(0); } } finally { cursor.close(); } } throw new IllegalArgumentException("Unable to find or allocate a thread ID."); }
Example #4
Source File: MediaStoreHack.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
public static Uri getUriFromFile(final String path, Context context) { ContentResolver resolver = context.getContentResolver(); Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"), new String[]{BaseColumns._ID}, MediaStore.MediaColumns.DATA + " = ?", new String[]{path}, MediaStore.MediaColumns.DATE_ADDED + " desc"); filecursor.moveToFirst(); if (filecursor.isAfterLast()) { filecursor.close(); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, path); return resolver.insert(MediaStore.Files.getContentUri("external"), values); } else { int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID)); Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath( Integer.toString(imageId)).build(); filecursor.close(); return uri; } }
Example #5
Source File: AndroidPathUtils.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
/** * Get an Uri from an file path. * * @param path The file path. * @return The Uri. */ public static Uri getUriFromFile(final String path, final Context c) { ContentResolver resolver = c.getContentResolver(); Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"), new String[] {BaseColumns._ID}, MediaColumns.DATA + " = ?", new String[] {path}, MediaColumns.DATE_ADDED + " desc"); if (filecursor == null) { return null; } filecursor.moveToFirst(); if (filecursor.isAfterLast()) { filecursor.close(); ContentValues values = new ContentValues(); values.put(MediaColumns.DATA, path); return resolver.insert(MediaStore.Files.getContentUri("external"), values); } else { int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID)); Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath( Integer.toString(imageId)).build(); filecursor.close(); return uri; } }
Example #6
Source File: StorageHelper.java From leafpicrevived with GNU General Public License v3.0 | 6 votes |
/** * Get an Uri from an file path. * * @param path The file path. * @return The Uri. */ private static Uri getUriFromFile(Context context, final String path) { ContentResolver resolver = context.getContentResolver(); Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"), new String[]{BaseColumns._ID}, MediaStore.MediaColumns.DATA + " = ?", new String[]{path}, MediaStore.MediaColumns.DATE_ADDED + " desc"); if (filecursor == null) { return null; } filecursor.moveToFirst(); if (filecursor.isAfterLast()) { filecursor.close(); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, path); return resolver.insert(MediaStore.Files.getContentUri("external"), values); } else { int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID)); Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath( Integer.toString(imageId)).build(); filecursor.close(); return uri; } }
Example #7
Source File: ContactsServicePlugin.java From flutter_contacts with MIT License | 6 votes |
private Cursor getCursorForPhone(String phone) { if (phone.isEmpty()) return null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone)); String[] projection = new String[]{BaseColumns._ID}; ArrayList<String> contactIds = new ArrayList<>(); Cursor phoneCursor = contentResolver.query(uri, projection, null, null, null); while (phoneCursor != null && phoneCursor.moveToNext()){ contactIds.add(phoneCursor.getString(phoneCursor.getColumnIndex(BaseColumns._ID))); } if (phoneCursor!= null) phoneCursor.close(); if (!contactIds.isEmpty()) { String contactIdsListString = contactIds.toString().replace("[", "(").replace("]", ")"); String contactSelection = ContactsContract.Data.CONTACT_ID + " IN " + contactIdsListString; return contentResolver.query(ContactsContract.Data.CONTENT_URI, PROJECTION, contactSelection, null, null); } return null; }
Example #8
Source File: PlaylistsUtil.java From Music-Player with GNU General Public License v3.0 | 6 votes |
public static String getNameForPlaylist(@NonNull final Context context, final long id) { try { Cursor cursor = context.getContentResolver().query(EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.PlaylistsColumns.NAME}, BaseColumns._ID + "=?", new String[]{String.valueOf(id)}, null); if (cursor != null) { try { if (cursor.moveToFirst()) { return cursor.getString(0); } } finally { cursor.close(); } } } catch (SecurityException ignored) { } return ""; }
Example #9
Source File: TaskDao.java From flutter_downloader with BSD 3-Clause "New" or "Revised" License | 6 votes |
public DownloadTask loadTask(String taskId) { SQLiteDatabase db = dbHelper.getReadableDatabase(); String whereClause = TaskContract.TaskEntry.COLUMN_NAME_TASK_ID + " = ?"; String[] whereArgs = new String[]{taskId}; Cursor cursor = db.query( TaskContract.TaskEntry.TABLE_NAME, projection, whereClause, whereArgs, null, null, BaseColumns._ID + " DESC", "1" ); DownloadTask result = null; while (cursor.moveToNext()) { result = parseCursor(cursor); } cursor.close(); return result; }
Example #10
Source File: ConnectionsFragment.java From FireFiles with Apache License 2.0 | 6 votes |
public boolean onPopupMenuItemClick(MenuItem item, int position) { final Cursor cursor = mAdapter.getItem(position); int connection_id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); final int id = item.getItemId(); switch (id) { case R.id.menu_edit: editConnection(connection_id); return true; case R.id.menu_delete: if(!networkConnection.type.equals(SERVER)) { deleteConnection(connection_id); } else { ((BaseActivity)getActivity()) .showSnackBar("Default server connection can't be deleted", Snackbar.LENGTH_SHORT); } return true; default: return false; } }
Example #11
Source File: DownloadsDB.java From QtAndroidTools with MIT License | 6 votes |
private DownloadsDB(Context paramContext) { this.mHelper = new DownloadsContentDBHelper(paramContext); final SQLiteDatabase sqldb = mHelper.getReadableDatabase(); // Query for the version code, the row ID of the metadata (for future // updating) the status and the flags Cursor cur = sqldb.rawQuery("SELECT " + MetadataColumns.APKVERSION + "," + BaseColumns._ID + "," + MetadataColumns.DOWNLOAD_STATUS + "," + MetadataColumns.FLAGS + " FROM " + MetadataColumns.TABLE_NAME + " LIMIT 1", null); if (null != cur && cur.moveToFirst()) { mVersionCode = cur.getInt(0); mMetadataRowID = cur.getLong(1); mStatus = cur.getInt(2); mFlags = cur.getInt(3); cur.close(); } mDownloadsDB = this; }
Example #12
Source File: ExplorerProvider.java From FireFiles with Apache License 2.0 | 6 votes |
private void createTablesV2(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_CONNECTION + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ConnectionColumns.NAME + " TEXT," + ConnectionColumns.TYPE + " TEXT," + ConnectionColumns.SCHEME + " TEXT," + ConnectionColumns.PATH + " TEXT," + ConnectionColumns.HOST + " TEXT," + ConnectionColumns.PORT + " INTEGER," + ConnectionColumns.USERNAME + " TEXT," + ConnectionColumns.PASSWORD + " TEXT," + ConnectionColumns.ANONYMOUS_LOGIN + " BOOLEAN," + "UNIQUE (" + ConnectionColumns.NAME + ", " + ConnectionColumns.HOST + ", " + ConnectionColumns.PATH + ") ON CONFLICT REPLACE " + ")"); addDefaultServer(db); }
Example #13
Source File: PlaylistsUtil.java From VinylMusicPlayer with GNU General Public License v3.0 | 6 votes |
public static String getNameForPlaylist(@NonNull final Context context, final long id) { try { Cursor cursor = context.getContentResolver().query(EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.PlaylistsColumns.NAME}, BaseColumns._ID + "=?", new String[]{String.valueOf(id)}, null); if (cursor != null) { try { if (cursor.moveToFirst()) { return cursor.getString(0); } } finally { cursor.close(); } } } catch (SecurityException ignored) { } return ""; }
Example #14
Source File: Util.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
public static final int getSongCountForPlaylist(final Context context, final long playlistId) { Cursor c = context.getContentResolver().query( MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId), new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null); if (c != null) { int count = 0; if (c.moveToFirst()) { count = c.getCount(); } c.close(); c = null; return count; } return 0; }
Example #15
Source File: NetworkConnection.java From FireFiles with Apache License 2.0 | 6 votes |
public static NetworkConnection fromConnectionId(Context context, int id) { Cursor cursor = null; NetworkConnection networkConnection = null; try { cursor = context.getContentResolver() .query(ExplorerProvider.buildConnection(), null, BaseColumns._ID + "=? " , new String[]{Integer.toString(id)}, null); if (null != cursor && cursor.moveToFirst()) { networkConnection = NetworkConnection.fromConnectionsCursor(cursor); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + NetworkStorageProvider.AUTHORITY + ": " + e); Crashlytics.logException(e); } finally { IoUtils.closeQuietly(cursor); } return networkConnection; }
Example #16
Source File: ExplorerProvider.java From FireFiles with Apache License 2.0 | 6 votes |
private void createTablesV2(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_CONNECTION + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ConnectionColumns.NAME + " TEXT," + ConnectionColumns.TYPE + " TEXT," + ConnectionColumns.SCHEME + " TEXT," + ConnectionColumns.PATH + " TEXT," + ConnectionColumns.HOST + " TEXT," + ConnectionColumns.PORT + " INTEGER," + ConnectionColumns.USERNAME + " TEXT," + ConnectionColumns.PASSWORD + " TEXT," + ConnectionColumns.ANONYMOUS_LOGIN + " BOOLEAN," + "UNIQUE (" + ConnectionColumns.NAME + ", " + ConnectionColumns.HOST + ", " + ConnectionColumns.PATH + ") ON CONFLICT REPLACE " + ")"); addDefaultServer(db); }
Example #17
Source File: NetworkStorageProvider.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateConnections() { Cursor cursor = null; mRoots.clear(); try { cursor = getContext().getContentResolver().query(ExplorerProvider.buildConnection(), null, null, null, null); while (cursor.moveToNext()) { int id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); mRoots.put(networkConnection.getHost(), networkConnection); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + ExplorerProvider.AUTHORITY + ": " + e); Crashlytics.logException(e); } finally { IoUtils.closeQuietly(cursor); } notifyRootsChanged(getContext()); }
Example #18
Source File: NetworkConnection.java From FireFiles with Apache License 2.0 | 6 votes |
public static NetworkConnection fromConnectionId(Context context, int id) { Cursor cursor = null; NetworkConnection networkConnection = null; try { cursor = context.getContentResolver() .query(ExplorerProvider.buildConnection(), null, BaseColumns._ID + "=? " , new String[]{Integer.toString(id)}, null); if (null != cursor && cursor.moveToFirst()) { networkConnection = NetworkConnection.fromConnectionsCursor(cursor); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + NetworkStorageProvider.AUTHORITY + ": " + e); Crashlytics.logException(e); } finally { IoUtils.closeQuietly(cursor); } return networkConnection; }
Example #19
Source File: ConnectionsFragment.java From FireFiles with Apache License 2.0 | 6 votes |
public boolean onPopupMenuItemClick(MenuItem item, int position) { final Cursor cursor = mAdapter.getItem(position); int connection_id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); final int id = item.getItemId(); switch (id) { case R.id.menu_edit: editConnection(connection_id); return true; case R.id.menu_delete: if(!networkConnection.type.equals(SERVER)) { deleteConnection(connection_id); } else { ((BaseActivity)getActivity()) .showSnackBar("Default server connection can't be deleted", Snackbar.LENGTH_SHORT); } return true; default: return false; } }
Example #20
Source File: ExplorerProvider.java From FireFiles with Apache License 2.0 | 6 votes |
private void createTablesV2(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_CONNECTION + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + ConnectionColumns.NAME + " TEXT," + ConnectionColumns.TYPE + " TEXT," + ConnectionColumns.SCHEME + " TEXT," + ConnectionColumns.PATH + " TEXT," + ConnectionColumns.HOST + " TEXT," + ConnectionColumns.PORT + " INTEGER," + ConnectionColumns.USERNAME + " TEXT," + ConnectionColumns.PASSWORD + " TEXT," + ConnectionColumns.ANONYMOUS_LOGIN + " BOOLEAN," + "UNIQUE (" + ConnectionColumns.NAME + ", " + ConnectionColumns.HOST + ", " + ConnectionColumns.PATH + ") ON CONFLICT REPLACE " + ")"); addDefaultServer(db); }
Example #21
Source File: NetworkStorageProvider.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateConnections() { Cursor cursor = null; mRoots.clear(); try { cursor = getContext().getContentResolver().query(ExplorerProvider.buildConnection(), null, null, null, null); while (cursor.moveToNext()) { int id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); mRoots.put(networkConnection.getHost(), networkConnection); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + ExplorerProvider.AUTHORITY + ": " + e); CrashReportingManager.logException(e); } finally { IoUtils.closeQuietly(cursor); } notifyRootsChanged(getContext()); }
Example #22
Source File: ExplorerProvider.java From FireFiles with Apache License 2.0 | 6 votes |
private void createTablesV3(SQLiteDatabase db) { db.execSQL("CREATE TABLE " + TABLE_STORAGE + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + StorageColumns.NAME + " TEXT," + StorageColumns.TYPE + " TEXT," + StorageColumns.SCHEME + " TEXT," + StorageColumns.PATH + " TEXT," + StorageColumns.HOST + " TEXT," + StorageColumns.PORT + " INTEGER," + StorageColumns.USERNAME + " TEXT," + StorageColumns.PASSWORD + " TEXT," + StorageColumns.ANONYMOUS_LOGIN + " BOOLEAN," + "UNIQUE (" + StorageColumns.NAME + ", " + StorageColumns.HOST + ", " + StorageColumns.PATH + ") ON CONFLICT REPLACE " + ")"); }
Example #23
Source File: ConnectionsFragment.java From FireFiles with Apache License 2.0 | 6 votes |
public boolean onPopupMenuItemClick(MenuItem item, int position) { final Cursor cursor = mAdapter.getItem(position); int connection_id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); final int id = item.getItemId(); switch (id) { case R.id.menu_edit: editConnection(connection_id); return true; case R.id.menu_delete: if(!networkConnection.type.equals(SERVER)) { deleteConnection(connection_id); } else { ((BaseActivity)getActivity()) .showSnackBar("Default server connection can't be deleted", Snackbar.LENGTH_SHORT); } return true; default: return false; } }
Example #24
Source File: NetworkStorageProvider.java From FireFiles with Apache License 2.0 | 6 votes |
public void updateConnections() { Cursor cursor = null; mRoots.clear(); try { cursor = getContext().getContentResolver().query(ExplorerProvider.buildConnection(), null, null, null, null); while (cursor.moveToNext()) { int id = getCursorInt(cursor, BaseColumns._ID); NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor); mRoots.put(networkConnection.getHost(), networkConnection); } } catch (Exception e) { Log.w(TAG, "Failed to load some roots from " + ExplorerProvider.AUTHORITY + ": " + e); Crashlytics.logException(e); } finally { IoUtils.closeQuietly(cursor); } notifyRootsChanged(getContext()); }
Example #25
Source File: FavLoader.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
/** * Creates a cursor that contains contacts group corresponding to an sip * account. */ private Cursor createContentCursorFor(SipProfile account) { Cursor c = null; if(!TextUtils.isEmpty(account.android_group)) { c = ContactsWrapper.getInstance().getContactsByGroup(getContext(), account.android_group); } if(c != null) { return c; } MatrixCursor mc = new MatrixCursor (new String[] { BaseColumns._ID, ContactsWrapper.FIELD_TYPE }); mc.addRow(new Object[] {account.id, ContactsWrapper.TYPE_CONFIGURE}); return mc; }
Example #26
Source File: PlaylistsUtil.java From MusicPlayer with GNU General Public License v3.0 | 6 votes |
public static String getNameForPlaylist(@NonNull final Context context, final long id) { try { Cursor cursor = context.getContentResolver().query(EXTERNAL_CONTENT_URI, new String[]{MediaStore.Audio.PlaylistsColumns.NAME}, BaseColumns._ID + "=?", new String[]{String.valueOf(id)}, null); if (cursor != null) { try { if (cursor.moveToFirst()) { return cursor.getString(0); } } finally { cursor.close(); } } } catch (SecurityException ignored) { } return ""; }
Example #27
Source File: ContractClassUnitTest.java From android-dev-challenge with Apache License 2.0 | 5 votes |
@Test public void inner_class_type_correct() throws Exception { Class[] innerClasses = WaitlistContract.class.getDeclaredClasses(); assertEquals("Cannot find inner class to complete unit test", 1, innerClasses.length); Class entryClass = innerClasses[0]; assertTrue("Inner class should implement the BaseColumns interface", BaseColumns.class.isAssignableFrom(entryClass)); assertTrue("Inner class should be final", Modifier.isFinal(entryClass.getModifiers())); assertTrue("Inner class should be static", Modifier.isStatic(entryClass.getModifiers())); }
Example #28
Source File: ContractClassUnitTest.java From android-dev-challenge with Apache License 2.0 | 5 votes |
@Test public void inner_class_type_correct() throws Exception { Class[] innerClasses = WaitlistContract.class.getDeclaredClasses(); assertEquals("Cannot find inner class to complete unit test", 1, innerClasses.length); Class entryClass = innerClasses[0]; assertTrue("Inner class should implement the BaseColumns interface", BaseColumns.class.isAssignableFrom(entryClass)); assertTrue("Inner class should be final", Modifier.isFinal(entryClass.getModifiers())); assertTrue("Inner class should be static", Modifier.isStatic(entryClass.getModifiers())); }
Example #29
Source File: PlaylistLoader.java From Orin with GNU General Public License v3.0 | 5 votes |
@Nullable public static Cursor makePlaylistCursor(@NonNull final Context context, final String selection, final String[] values) { try { return context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[]{ /* 0 */ BaseColumns._ID, /* 1 */ PlaylistsColumns.NAME }, selection, values, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER); } catch (SecurityException e) { return null; } }
Example #30
Source File: MediaDocumentsProvider.java From FireFiles with Apache License 2.0 | 5 votes |
private boolean isEmpty(Uri uri) { final ContentResolver resolver = getContext().getContentResolver(); final long token = Binder.clearCallingIdentity(); Cursor cursor = null; try { cursor = resolver.query(uri, new String[] { BaseColumns._ID }, null, null, null); return (cursor == null) || (cursor.getCount() == 0); } finally { IoUtils.closeQuietly(cursor); Binder.restoreCallingIdentity(token); } }