Example usage for android.database Cursor moveToFirst

List of usage examples for android.database Cursor moveToFirst

Introduction

In this page you can find the example usage for android.database Cursor moveToFirst.

Prototype

boolean moveToFirst();

Source Link

Document

Move the cursor to the first row.

Usage

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    cursor.moveToFirst();
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    return cursor.getString(column_index);
}

From source file:Main.java

public static void removeFromPlaylist(ContentResolver resolver, int audioId, long playlistId) {
    String[] cols = new String[] { "count(*)" };
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
    Cursor cur = resolver.query(uri, cols, null, null, null);
    cur.moveToFirst();
    final int base = cur.getInt(0);
    cur.close();// w w w.ja va 2s .  c o m
    ContentValues values = new ContentValues();

    resolver.delete(uri, MediaStore.Audio.Playlists.Members.AUDIO_ID + "=" + audioId, null);

}

From source file:Main.java

/**
 * Find a download with the specified name.  Returns -1 if none was
 * found.// ww w . ja v a2  s . c  o  m
 */
static long findPath(DownloadManager dm, String path) {
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterByStatus(
            DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_PENDING | DownloadManager.STATUS_RUNNING);
    Cursor c = dm.query(query);

    if (!c.moveToFirst())
        return -1;

    final int columnID = c.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
    final int columnLocalURI = c.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI);

    do {
        final String uri = c.getString(columnLocalURI);
        if (uri != null && uri.endsWith(path))
            return c.getLong(columnID);
    } while (c.moveToNext());

    return -1;
}

From source file:Main.java

public static void addToMediaStorePlaylist(ContentResolver resolver, int audioId, long playlistId) {
    String[] cols = new String[] { "count(*)" };
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
    Cursor cur = resolver.query(uri, cols, null, null, null);
    cur.moveToFirst();
    final int base = cur.getInt(0);
    cur.close();//  w  ww . j av  a2  s  .co m
    ContentValues values = new ContentValues();
    values.put(MediaStore.Audio.Playlists.Members.PLAY_ORDER, Integer.valueOf(base + audioId));
    values.put(MediaStore.Audio.Playlists.Members.AUDIO_ID, audioId);
    resolver.insert(uri, values);

}

From source file:Main.java

/**
 * Returns the system default ringtone URI {@link Uri}, or
 * the first available ringtone when the system default
 * does not exist (usually tablets)./*from  w  w w .j  av  a2 s.  com*/
 *
 * @param ctx the {@link Context}
 * @return Uri ringtone URI
 */
public static Uri getDefaultRingtoneUri(Context ctx, int type) {
    Uri uri;

    uri = RingtoneManager.getActualDefaultRingtoneUri(ctx, type);

    if (uri == null) {
        // The default ringtone doesn't exist - probably a tablet
        // Return the first available
        RingtoneManager rm = new RingtoneManager(ctx);
        rm.setType(type);

        Cursor cursor = rm.getCursor();
        cursor.moveToFirst();

        String idString = cursor.getString(RingtoneManager.ID_COLUMN_INDEX);
        String uriString = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        uri = Uri.parse(uriString + '/' + idString);

        cursor.close();

        return uri;
    } else {
        // Return system default ringtone
        return uri;
    }
}

From source file:Main.java

public static int getApnPortInt(Context context) {
    Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
    c.moveToFirst();
    if (c.isAfterLast()) {
        c.close();/*from  w w w .j  a  v a  2 s  . c om*/
        return -1;
    }
    int result = c.getInt(c.getColumnIndex(APN_PROP_PORT));
    return result;
}

From source file:Main.java

/**
 * Helper method to reslove a uri into a path.
 * //from   w  ww  .  j a v a 2s.  co m
 * @param contentURI
 *            a uri path
 * @return the path as a string
 */
public static String getRealPathFromURI(Uri contentURI, Context context) {
    Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    String path = cursor.getString(idx);
    cursor.close();
    return path;
}

From source file:Main.java

public static String getApnProxy(Context context) {
    Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
    c.moveToFirst();
    if (c.isAfterLast()) {
        c.close();//  w w  w. j a va  2s.  c  o  m
        return null;
    }
    String strResult = c.getString(c.getColumnIndex(APN_PROP_PROXY));
    c.close();
    return strResult;
}

From source file:Main.java

public static String getApn(Context context) {
    Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null);
    c.moveToFirst();
    if (c.isAfterLast()) {
        c.close();//from  www .j a v a 2 s. c om
        return null;
    }

    String strResult = c.getString(c.getColumnIndex(APN_PROP_APN));
    c.close();
    return strResult;
}

From source file:Main.java

/**
 * Get the unread count for the given shortcut info
 * @param c cursor holding the unread counts
 * @param packageName the package we are looking for
 * @return int of the unread count/*from w w w .  j a v  a2s. c o  m*/
 */
public static int getUnreadCount(Cursor c, String packageName) {
    int count = 0;

    try {
        if (c.moveToFirst()) {
            String currName = null;
            do {
                currName = c.getString(c.getColumnIndex("package_name"));
                if (currName.equals(packageName)) {
                    count = c.getInt(c.getColumnIndex("count"));
                }
            } while (c.moveToNext());
        }
    } catch (Exception e) {

    }

    return count;
}