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:Main.java

public static String idAsPrimaryKey() {
    return BaseColumns._ID + " INTEGER PRIMARY KEY";
}

From source file:Main.java

public static String increment(boolean increment, String table, String column, long _id) {
    return new StringBuilder("UPDATE ").append(table).append(" ").append(" SET ").append(column).append("=")
            .append(column).append(increment ? "+1" : "-1").append(" WHERE ").append(BaseColumns._ID)
            .append("=").append(_id).toString();
}

From source file:Main.java

public static void createTable(final SQLiteDatabase db, final String tableName,
        final String[] columnsDefinition) {
    String queryStr = "CREATE TABLE " + tableName + "(" + BaseColumns._ID + " INTEGER  PRIMARY KEY ,";
    // Add the columns now, Increase by 2
    for (int i = 0; i < (columnsDefinition.length - 1); i += 2) {
        if (i != 0) {
            queryStr += ",";
        }//w w w  . ja v a 2s  .  c om
        queryStr += columnsDefinition[i] + " " + columnsDefinition[i + 1];
    }

    queryStr += ");";

    db.execSQL(queryStr);
}

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// w w  w. 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;
}

From source file:Main.java

public static String createTableSql(Class<?> classs, String tableName, String... extraColumns) {
    mBuffer.setLength(0);//from www .  j  a  va 2s .c  o  m
    mBuffer.append("CREATE TABLE IF NOT EXISTS ");
    if (!TextUtils.isEmpty(tableName)) {
        mBuffer.append(tableName);
    } else {
        String className = classs.getSimpleName();
        if (className.contains("[]")) {
            throw new IllegalArgumentException("Can not create array class table");
        }
        mBuffer.append(classs.getSimpleName());
    }
    mBuffer.append("(" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, ");
    Field[] fields = classs.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if (field.getType() == Integer.class) {
            mBuffer.append(field.getName() + " INTEGER,");
        } else if (field.getType() == Double.class || field.getType() == Float.class) {
            mBuffer.append(field.getName() + " REAL,");
        } else if (field.getType() == String.class) {
            mBuffer.append(field.getName() + " TEXT,");
        } else if (field.getType() == Boolean.class) {
            mBuffer.append(field.getName() + " INTEGER,");
        } else if (field.getType() == List.class || field.getType() == ArrayList.class) {
            mBuffer.append(field.getName() + " TEXT,");
        }
    }
    if (extraColumns != null && extraColumns.length != 0) {
        for (int i = 0; i < extraColumns.length; i++) {
            mBuffer.append(extraColumns[i]);
            if (i != extraColumns.length - 1) {
                mBuffer.append(",");
            } else {
                mBuffer.append(")");
            }
        }
    }
    return mBuffer.toString();
}

From source file:Main.java

/**
 * Returns the Id for an artist./*from w  ww . jav a 2s .c  o m*/
 *
 * @param context The {@link Context} to use.
 * @param name The name of the artist.
 * @return The ID for an artist.
 */
public static final long getIdForArtist(final Context context, final String name) {
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,
            new String[] { BaseColumns._ID }, ArtistColumns.ARTIST + "=?", new String[] { name },
            ArtistColumns.ARTIST);
    int id = -1;
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            id = cursor.getInt(0);
        }
        cursor.close();
        cursor = null;
    }
    return id;
}

From source file:Main.java

/**
 * Returns a fancy search query cursor//from w w w . j  a  v  a  2s.c  om
 *
 * @param context
 * @param query   query string
 * @return cursor of the results
 */
public static Cursor createSearchQueryCursor(final Context context, final String query) {
    final Uri uri = Uri.parse("content://media/external/audio/search/fancy/" + Uri.encode(query));
    final String[] projection = new String[] { BaseColumns._ID, MediaStore.Audio.Media.MIME_TYPE,
            MediaStore.Audio.Artists.ARTIST, MediaStore.Audio.Albums.ALBUM, MediaStore.Audio.Media.TITLE,
            "data1", "data2" };

    // no selection/selection/sort args - they are ignored by fancy search anyways
    return context.getContentResolver().query(uri, projection, null, null, null);
}

From source file:Main.java

/**
 * Returns The ID for a playlist.//  w  ww.  j a v  a 2 s  . c o m
 *
 * @param context The {@link Context} to use.
 * @param name The name of the playlist.
 * @return The ID for a playlist.
 */
public static final long getIdForPlaylist(final Context context, final String name) {
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
            new String[] { BaseColumns._ID }, PlaylistsColumns.NAME + "=?", new String[] { name },
            PlaylistsColumns.NAME);
    int id = -1;
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            id = cursor.getInt(0);
        }
        cursor.close();
        cursor = null;
    }
    return id;
}

From source file:Main.java

/**
 * Returns the ID for an album.//from   w  w  w . ja v  a2 s  .c  om
 *
 * @param context The {@link Context} to use.
 * @param albumName The name of the album.
 * @param artistName The name of the artist
 * @return The ID for an album.
 */
public static final long getIdForAlbum(final Context context, final String albumName, final String artistName) {
    Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI,
            new String[] { BaseColumns._ID }, AlbumColumns.ALBUM + "=? AND " + AlbumColumns.ARTIST + "=?",
            new String[] { albumName, artistName }, AlbumColumns.ALBUM);
    int id = -1;
    if (cursor != null) {
        cursor.moveToFirst();
        if (!cursor.isAfterLast()) {
            id = cursor.getInt(0);
        }
        cursor.close();
        cursor = null;
    }
    return id;
}

From source file:com.dvdprime.mobile.android.adapter.DocumentSuggestionsAdapter.java

public static MatrixCursor getCursor(String query) {
    //  ? ?? //from   w  w  w  .ja  v a  2 s.c  o m
    final String[] COLUMNS = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };

    MatrixCursor cursor = new MatrixCursor(COLUMNS);
    cursor.addRow(new Object[] { 1, query, " " });
    cursor.addRow(new Object[] { 2, query, "ID " });
    cursor.addRow(new Object[] { 6, query, " " });
    cursor.addRow(new Object[] { 4, query, "? " });
    cursor.addRow(new Object[] { 7, query, "  " });

    return cursor;
}