List of usage examples for android.provider BaseColumns _ID
String _ID
To view the source code for android.provider BaseColumns _ID.
Click Source Link
From source file:com.appsimobile.appsii.module.home.provider.HomeContentProvider.java
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { selection = fixWhereProjection(uri, selection); SqlArguments args = new SqlArguments(uri, selection, selectionArgs); SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); String tables = createTablesFromTableQuery(args.table); qb.setTables(tables);//from ww w . jav a 2 s . c om Map<String, String> projectionMap = getProjectionMapForTable(args.table); if (projectionMap != null) { qb.setProjectionMap(projectionMap); qb.setStrict(true); } SQLiteDatabase db = mOpenHelper.getWritableDatabase(); if (HomeContract.CELLS_TABLE_NAME.equals(args.table)) { sortOrder = fixSortOrder(sortOrder); } String where = args.where; if (HomeContract.HOTSPOT_PAGES_DETAILS_TABLE_NAME.equals(args.table)) { where = "_ht." + BaseColumns._ID + "=" + ContentUris.parseId(uri); } Cursor result = qb.query(db, projection, where, args.args, null, null, sortOrder); result.setNotificationUri(getContext().getContentResolver(), uri); return result; }
From source file:saschpe.birthdays.service.CalendarSyncService.java
private static Cursor getContactsEvents(Context context, ContentResolver contentResolver) { // Account blacklist from our provider List<Account> accountBlacklist = AccountProviderHelper.getAccountList(context); List<String> addedEventsIdentifiers = new ArrayList<>(); /* 1. Get all raw contacts with their corresponding Account name and type (only raw * contacts get Account affiliation) */ Uri rawContactsUri = ContactsContract.RawContacts.CONTENT_URI; String[] rawContactsProjection = new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.CONTACT_ID, ContactsContract.RawContacts.DISPLAY_NAME_PRIMARY, ContactsContract.RawContacts.ACCOUNT_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE }; Cursor rawContacts = contentResolver.query(rawContactsUri, rawContactsProjection, null, null, null); /* 2. Go over all raw contacts and check if the Account is allowed. If account is allowed, * get display name and lookup key and all events for this contact. Build a new * MatrixCursor out of this data that can be used. */ String[] columns = new String[] { BaseColumns._ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.LOOKUP_KEY, ContactsContract.CommonDataKinds.Event.START_DATE, ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.LABEL, }; MatrixCursor mc = new MatrixCursor(columns); int mcIndex = 0; try {// ww w. jav a2 s . co m while (rawContacts != null && rawContacts.moveToNext()) { long rawId = rawContacts.getLong(rawContacts.getColumnIndex(ContactsContract.RawContacts._ID)); String accountType = rawContacts .getString(rawContacts.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); String accountName = rawContacts .getString(rawContacts.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_NAME)); // 2a. Check if Account is allowed (not in blacklist) boolean addEvent; if (TextUtils.isEmpty(accountType) || TextUtils.isEmpty(accountName)) { // Workaround: Simply add events without proper Account addEvent = true; } else { Account account = new Account(accountName, accountType); addEvent = !accountBlacklist.contains(account); } if (addEvent) { String displayName = null; String lookupKey = null; // 2b. Get display name and lookup key from normal contact table String[] displayProjection = new String[] { ContactsContract.Data.RAW_CONTACT_ID, ContactsContract.Data.DISPLAY_NAME, ContactsContract.Data.LOOKUP_KEY }; String displayWhere = ContactsContract.Data.RAW_CONTACT_ID + "= ?"; String[] displaySelectionArgs = new String[] { String.valueOf(rawId) }; Cursor displayCursor = contentResolver.query(ContactsContract.Data.CONTENT_URI, displayProjection, displayWhere, displaySelectionArgs, null); try { if (displayCursor != null && displayCursor.moveToNext()) { displayName = displayCursor .getString(displayCursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); lookupKey = displayCursor .getString(displayCursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY)); } } finally { if (displayCursor != null && !displayCursor.isClosed()) { displayCursor.close(); } } /* 2c. Get all events for this raw contact. We don't get this information for * the (merged) contact table, but from the raw contact. If we would query * this information from the contact table, we would also get events that * should have been filtered. */ Uri thisRawContactUri = ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, rawId); Uri entityUri = Uri.withAppendedPath(thisRawContactUri, ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY); String[] eventsProjection = new String[] { ContactsContract.RawContacts._ID, ContactsContract.RawContacts.Entity.DATA_ID, ContactsContract.CommonDataKinds.Event.START_DATE, ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.LABEL }; String eventsWhere = ContactsContract.RawContacts.Entity.MIMETYPE + " = ? AND " + ContactsContract.RawContacts.Entity.DATA_ID + " IS NOT NULL"; String[] eventsSelectionArgs = new String[] { ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE }; Cursor eventsCursor = contentResolver.query(entityUri, eventsProjection, eventsWhere, eventsSelectionArgs, null); try { while (eventsCursor != null && eventsCursor.moveToNext()) { String startDate = eventsCursor.getString( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE)); int type = eventsCursor.getInt( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE)); String label = eventsCursor.getString( eventsCursor.getColumnIndex(ContactsContract.CommonDataKinds.Event.LABEL)); /* 2d. Add this information to our MatrixCursor if not already added * previously. If two Event Reminder accounts have the same contact * with duplicated events, the event will already be in the HashSet * addedEventsIdentifiers. * * eventIdentifier does not include startDate, because the * String formats of startDate differ between accounts. */ //String eventIdentifier = lookupKey + type + label; String eventIdentifier = lookupKey + type; if (addedEventsIdentifiers.contains(eventIdentifier)) { Log.d(TAG, "Duplicate event was not added!"); } else { Log.d(TAG, "Event was added with identifier " + eventIdentifier); addedEventsIdentifiers.add(eventIdentifier); mc.newRow().add(mcIndex).add(displayName).add(lookupKey).add(startDate).add(type) .add(label); mcIndex++; } } } finally { if (eventsCursor != null && !eventsCursor.isClosed()) { eventsCursor.close(); } } } } } finally { if (rawContacts != null && !rawContacts.isClosed()) { rawContacts.close(); } } /*if (BuildConfig.DEBUG) { DatabaseUtils.dumpCursor(mc); }*/ return mc; }
From source file:fr.openbike.android.database.OpenBikeDBAdapter.java
public Cursor getStationsMatches(String query, String[] columns) { String table = STATIONS_VIRTUAL_TABLE; try {// w w w.ja va2s . c o m Integer.parseInt(query); table = BaseColumns._ID; } catch (NumberFormatException ex) { } query += "*"; // Network is not in argument list because when I do so, it doesn't work // ! String s = "SELECT vs._id, vs._id as " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID + ", 'n ' || vs._id as " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ", vs.name as " + SearchManager.SUGGEST_COLUMN_TEXT_1 + " FROM" + " virtual_stations vs WHERE " + table + " MATCH ? AND vs.network = " + mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE, AbstractPreferencesActivity.NO_NETWORK) + ";"; Cursor cursor = mDb.rawQuery(s, new String[] { query }); /* * Cursor cursor = mDb.query(STATIONS_VIRTUAL_TABLE, new String[] { * BaseColumns._ID, "'n ' || " + BaseColumns._ID + " as " + * SearchManager.SUGGEST_COLUMN_TEXT_2, BaseColumns._ID + " as " + * SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, KEY_NAME + " as " + * SearchManager.SUGGEST_COLUMN_TEXT_1 }, table + " MATCH ? AND " + * KEY_NETWORK + " = ?", new String[] { query, * String.valueOf(mCurrentNetwork) }, null, null, null); */ /* * Cursor cursor = mDb.rawQuery( "SELECT _id " + * SearchManager.SUGGEST_COLUMN_TEXT_2 + ", _id " + * SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID + ", name " + * SearchManager.SUGGEST_COLUMN_TEXT_1 + " FROMvirtual_stations;" * "WHERE " + table + " MATCH ?;", null new String[] { query, * String.valueOf(mCurrentNetwork) }); */ if (cursor == null) { return null; } /* * else if (!cursor.moveToFirst()) { cursor.close(); return null; * * } */ return cursor; }
From source file:com.andrew.apollo.utils.MusicUtils.java
public static Song getSong(Context context, final long songId) { final StringBuilder mSelection = new StringBuilder(BaseColumns._ID + "=?"); mSelection.append(" AND " + AudioColumns.IS_MUSIC + "=1"); mSelection.append(" AND " + AudioColumns.TITLE + " != ''"); //$NON-NLS-2$ final Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[] { /* 0 */ BaseColumns._ID,//from w w w . jav a 2s . c om /* 1 */ AudioColumns.TITLE, /* 2 */ AudioColumns.ARTIST, /* 3 */ AudioColumns.ALBUM, /* 4 */ AudioColumns.DURATION }, mSelection.toString(), new String[] { String.valueOf(songId) }, PreferenceUtils.getInstance(context).getSongSortOrder()); if (cursor != null && cursor.getCount() == 1) { cursor.moveToFirst(); return new Song(songId, cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getInt(4)); } else { return null; } }
From source file:net.voxcorp.voxmobile.ui.account.AccountsEditListFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(getActivity(), SipProfile.ACCOUNT_URI, new String[] { SipProfile.FIELD_ID + " AS " + BaseColumns._ID, SipProfile.FIELD_ID, SipProfile.FIELD_DISPLAY_NAME, SipProfile.FIELD_WIZARD, SipProfile.FIELD_ACTIVE, SipProfile.FIELD_PROXY }, null, null, null);//from w w w . java2s. co m }
From source file:org.catnut.fragment.ProfileFragment.java
private void injectProfile(Cursor cursor) { // ?//w w w .j ava 2s .c om mUid = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)); mAvatarUrl = cursor.getString(cursor.getColumnIndex(User.avatar_large)); mAvatarHdUrl = cursor.getString(cursor.getColumnIndex(User.avatar_hd)); mVerified = CatnutUtils.getBoolean(cursor, User.verified); mRemark = cursor.getString(cursor.getColumnIndex(User.remark)); mDescription = cursor.getString(cursor.getColumnIndex(User.description)); mLocation = cursor.getString(cursor.getColumnIndex(User.location)); mProfileUrl = cursor.getString(cursor.getColumnIndex(User.profile_url)); mCoverUrl = cursor.getString(cursor.getColumnIndex(User.cover_image)); mVerifiedReason = cursor.getString(cursor.getColumnIndex(User.verified_reason)); // + mFollowing = CatnutUtils.getBoolean(cursor, User.following); // menu buildMenu(); // load?? if (!TextUtils.isEmpty(mCoverUrl)) { Picasso.with(getActivity()).load(mCoverUrl).placeholder(R.drawable.default_fantasy) .error(R.drawable.default_fantasy).into(profileTarget); } else { mPlaceHolder.setBackground(getResources().getDrawable(R.drawable.default_fantasy)); } // ? mTweetsCount.setOnClickListener(tweetsOnclickListener); CatnutUtils.setText(mTweetsCount, android.R.id.text1, cursor.getString(cursor.getColumnIndex(User.statuses_count))); CatnutUtils.setText(mTweetsCount, android.R.id.text2, getString(R.string.tweets)); // mFollowersCount.setOnClickListener(followersOnclickListener); CatnutUtils.setText(mFollowersCount, android.R.id.text1, cursor.getString(cursor.getColumnIndex(User.followers_count))); CatnutUtils.setText(mFollowersCount, android.R.id.text2, getString(R.string.followers)); // mFollowingsCount.setOnClickListener(followingsOnClickListener); CatnutUtils.setText(mFollowingsCount, android.R.id.text1, cursor.getString(cursor.getColumnIndex(User.friends_count))); CatnutUtils.setText(mFollowingsCount, android.R.id.text2, getString(R.string.followings)); // pager adapter, not fragment pager any more mViewPager.setAdapter(coverPager); mIndicator.setViewPager(mViewPager); }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param context The {@link Context} to use. * @param id The ID of the artist.//from w ww .j a v a 2 s. c o m * @return The song list for an artist. */ public static long[] getSongListForArtist(final Context context, final long id) { try { final String[] projection = new String[] { BaseColumns._ID }; final String selection = AudioColumns.ARTIST_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC + "=1"; Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, AudioColumns.ALBUM_KEY + "," + AudioColumns.TRACK); if (cursor != null) { final long[] mList = getSongListForCursor(cursor); cursor.close(); if (mList == null || mList.length == 0) { return sEmptyList; } return mList; } } catch (Throwable t) { return sEmptyList; } return sEmptyList; }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param cursor The {@link Cursor} used to perform our query. * @return The song list for a MIME type. *///from w w w . ja v a2 s . c om public static long[] getSongListForCursor(Cursor cursor) { if (cursor == null) { return sEmptyList; } final int len = cursor.getCount(); final long[] list = new long[len]; cursor.moveToFirst(); int columnIndex; try { columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID); } catch (final IllegalArgumentException notaplaylist) { columnIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID); } for (int i = 0; i < len; i++) { list[i] = cursor.getLong(columnIndex); cursor.moveToNext(); } cursor.close(); return list; }
From source file:com.android.bluetooth.map.BluetoothMapContent.java
public void dumpMmsTable() { if (D)//from w ww. ja va2 s.co m Log.d(TAG, "**** Dump of mms table ****"); Cursor c = mResolver.query(Mms.CONTENT_URI, MMS_PROJECTION, null, null, "_id DESC"); if (c != null) { if (D) Log.d(TAG, "c.getCount() = " + c.getCount()); c.moveToPosition(-1); while (c.moveToNext()) { printMms(c); long id = c.getLong(c.getColumnIndex(BaseColumns._ID)); printMmsAddr(id); printMmsParts(id); } c.close(); } else { Log.d(TAG, "query failed"); } }
From source file:bf.io.openshop.ux.MainActivity.java
/** * Show user search whisperer with generated suggestions. * * @param query actual search query * @param searchView corresponding search action view. *///w w w. j a va2 s . com private void showSearchSuggestions(String query, SearchView searchView) { if (searchSuggestionsAdapter != null && searchSuggestionsList != null) { Timber.d("Populate search adapter - mySuggestions.size(): %d", searchSuggestionsList.size()); final MatrixCursor c = new MatrixCursor(new String[] { BaseColumns._ID, "categories" }); for (int i = 0; i < searchSuggestionsList.size(); i++) { if (searchSuggestionsList.get(i) != null && searchSuggestionsList.get(i).toLowerCase().startsWith(query.toLowerCase())) c.addRow(new Object[] { i, searchSuggestionsList.get(i) }); } searchView.setSuggestionsAdapter(searchSuggestionsAdapter); searchSuggestionsAdapter.changeCursor(c); } else { Timber.e("Search adapter is null or search data suggestions missing"); } }