Example usage for android.provider BaseColumns _ID

List of usage examples for android.provider BaseColumns _ID

Introduction

In this page you can find the example usage for android.provider BaseColumns _ID.

Prototype

String _ID

To view the source code for android.provider BaseColumns _ID.

Click Source Link

Document

The unique ID for a row.

Usage

From source file:com.amaze.filemanager.utils.files.FileUtils.java

private static Uri fileToContentUri(Context context, String path, boolean isDirectory, String volume) {
    final String where = MediaStore.MediaColumns.DATA + " = ?";
    Uri baseUri;//from w w w. ja  va2 s .c o  m
    String[] projection;
    int mimeType = Icons.getTypeOfFile(path, isDirectory);

    switch (mimeType) {
    case Icons.IMAGE:
        baseUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        projection = new String[] { BaseColumns._ID };
        break;
    case Icons.VIDEO:
        baseUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        projection = new String[] { BaseColumns._ID };
        break;
    case Icons.AUDIO:
        baseUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        projection = new String[] { BaseColumns._ID };
        break;
    default:
        baseUri = MediaStore.Files.getContentUri(volume);
        projection = new String[] { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE };
    }

    ContentResolver cr = context.getContentResolver();
    Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null);
    try {
        if (c != null && c.moveToNext()) {
            boolean isValid = false;
            if (mimeType == Icons.IMAGE || mimeType == Icons.VIDEO || mimeType == Icons.AUDIO) {
                isValid = true;
            } else {
                int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
                isValid = type != 0;
            }

            if (isValid) {
                // Do not force to use content uri for no media files
                long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID));
                return Uri.withAppendedPath(baseUri, String.valueOf(id));
            }
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return null;
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use.
 * @param id The ID of the album./*from  w  w w .j a va 2  s .  c  o m*/
 * @return The song list for an album.
 */
public static long[] getSongListForAlbum(final Context context, final long id) {
    final String[] projection = new String[] { BaseColumns._ID };
    final String selection = AudioColumns.ALBUM_ID + "=" + id + " AND " + AudioColumns.IS_MUSIC + "=1";
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection,
            selection, null, AudioColumns.TRACK + ", " + MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
    if (cursor != null) {
        final long[] mList = getSongListForCursor(cursor);
        cursor.close();
        return mList;
    }
    return sEmptyList;
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public Cursor getStation(int id, String[] columns) throws SQLException {
    Cursor cursor = mDb.query(true, STATIONS_TABLE, columns,
            BaseColumns._ID + " = ? AND " + KEY_NETWORK + " = ?",
            new String[] { String.valueOf(id),
                    String.valueOf(mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE,
                            AbstractPreferencesActivity.NO_NETWORK)) },
            null, null, null, null);//from   w  ww . j  a v  a2s. c  om
    if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
        throw new SQLException("No Station found with ID " + id);
    }
    return cursor;
}

From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java

public static HashMap<String, SyncEntry> getLocalContacts(Account account) {
    Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
            .appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
            .appendQueryParameter(RawContacts.ACCOUNT_TYPE, account.type).build();
    HashMap<String, SyncEntry> localContacts = new HashMap<String, SyncEntry>();
    Cursor c1 = mContentResolver.query(rawContactUri,
            new String[] { BaseColumns._ID, UsernameColumn, PhotoTimestampColumn }, null, null, null);
    while (c1.moveToNext()) {
        SyncEntry entry = new SyncEntry();
        entry.raw_id = c1.getLong(c1.getColumnIndex(BaseColumns._ID));
        localContacts.put(c1.getString(1), entry);
    }//ww w  . j a  v  a 2  s  .  c  o m
    c1.close();
    return localContacts;
}

From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java

private int deleteSource(@NonNull final Uri uri, final String selection, final String[] selectionArgs) {
    // Opens the database object in "write" mode.
    final SQLiteDatabase db = databaseHelper.getWritableDatabase();
    int count;/*www.jav  a2s. c  om*/
    // Does the delete based on the incoming URI pattern.
    switch (MuzeiProvider.uriMatcher.match(uri)) {
    case SOURCES:
        // If the incoming pattern matches the general pattern for
        // sources, does a delete based on the incoming "where"
        // column and arguments.
        count = db.delete(MuzeiContract.Sources.TABLE_NAME, selection, selectionArgs);
        break;
    case SOURCE_ID:
        // If the incoming URI matches a single source ID, does the
        // delete based on the incoming data, but modifies the where
        // clause to restrict it to the particular source ID.
        String finalWhere = BaseColumns._ID + " = " + uri.getLastPathSegment();
        // If there were additional selection criteria, append them to the final WHERE clause
        if (selection != null)
            finalWhere = finalWhere + " AND " + selection;
        count = db.delete(MuzeiContract.Sources.TABLE_NAME, finalWhere, selectionArgs);
        break;
    default:
        throw new IllegalArgumentException("Unknown URI " + uri);
    }
    if (count > 0) {
        notifyChange(uri);
    }
    return count;
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public Cursor getNetwork(int id, String[] columns) {
    try {//from ww  w .j a v  a  2 s.c o m
        Cursor cursor = mDb.query(true, NETWORKS_TABLE, columns, BaseColumns._ID + " = ?",
                new String[] { String.valueOf(id) }, null, null, null, null);
        if ((cursor.getCount() == 0) || !cursor.moveToFirst()) {
            return null;
        }
        return cursor;
    } catch (Exception e) {
    }
    return null;
}

From source file:org.catnut.ui.ComposeTweetActivity.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Log.d(TAG, mCurKeywords);// w  w w  .j a va 2 s .c  om
    StringBuilder where = new StringBuilder();
    where.append(User.screen_name).append(" like ").append(CatnutUtils.like(mCurKeywords)).append(" or ")
            .append(User.remark).append(" like ").append(CatnutUtils.like(mCurKeywords));
    return CatnutUtils.getCursorLoader(this, CatnutProvider.parse(User.MULTIPLE),
            new String[] { User.screen_name, User.remark, BaseColumns._ID, }, where.toString(), null,
            User.TABLE, null, null, null);
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * @param context The {@link Context} to use.
 * @param id The ID of the genre./*from   ww w  .  j a v  a2s  . com*/
 * @return The song list for an genre.
 */
public static long[] getSongListForGenre(final Context context, final long id) {
    final String[] projection = new String[] { BaseColumns._ID };
    final StringBuilder selection = new StringBuilder();
    selection.append(AudioColumns.IS_MUSIC + "=1");
    selection.append(" AND " + MediaColumns.TITLE + "!=''");
    final Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external", id);
    Cursor cursor = context.getContentResolver().query(uri, projection, selection.toString(), null, null);
    if (cursor != null) {
        final long[] mList = getSongListForCursor(cursor);
        cursor.close();
        return mList;
    }
    return sEmptyList;
}

From source file:ru.valle.safetrade.SellActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        String scannedResult = data.getStringExtra("data");
        if (scannedResult != null) {
            switch (requestCode) {
            case REQUEST_SCAN_CONFIRMATION_CODE: {
                if (scannedResult.startsWith("cfrm")) {
                    checkConfirmationCodeToDecodeAddress(scannedResult);
                } else if (scannedResult.startsWith("passphrase")) {
                    showAlert(getString(R.string.not_confirmation_but_intermediate_code));
                } else {
                    showAlert(getString(R.string.not_confirmation_code));
                }//  w ww  .  j  a v  a 2s  .c  o  m
            }
                break;
            case REQUEST_SCAN_PRIVATE_KEY: {
                if (scannedResult.startsWith("6P")) {
                    savePrivateKey(scannedResult);
                } else {
                    showAlert(getString(R.string.not_encrypted_private_key));
                }
            }
                break;
            case REQUEST_SCAN_FINAL_ADDRESS: {
                final String address;
                if (scannedResult.startsWith(SCHEME_BITCOIN)) {
                    scannedResult = scannedResult.substring(SCHEME_BITCOIN.length());
                    int queryStartIndex = scannedResult.indexOf('?');
                    address = queryStartIndex == -1 ? scannedResult
                            : scannedResult.substring(0, queryStartIndex);
                } else if (scannedResult.startsWith("1")) {
                    address = scannedResult;
                } else {
                    showAlert(getString(R.string.not_address));
                    address = null;
                }
                if (!TextUtils.isEmpty(address)) {
                    finalAddressView.setText(address);
                    final long id = rowId;
                    new AsyncTask<Void, Void, Void>() {
                        @Override
                        protected Void doInBackground(Void... params) {
                            SQLiteDatabase db = DatabaseHelper.getInstance(SellActivity.this)
                                    .getWritableDatabase();
                            if (db != null) {
                                ContentValues cv = new ContentValues();
                                cv.put(DatabaseHelper.COLUMN_FINAL_ADDRESS, address);
                                db.update(DatabaseHelper.TABLE_HISTORY, cv, BaseColumns._ID + "=?",
                                        new String[] { String.valueOf(id) });
                            }
                            return null;
                        }
                    }.execute();
                }
            }
                break;
            }

        }
    }
}