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 getFileNameFromUri(Uri uri, Activity activity) {
    String[] projection = { MediaStore.Images.ImageColumns.DISPLAY_NAME };
    String fileName = null;/*from  ww  w  .j  a v  a2  s.  c om*/
    Cursor c = activity.managedQuery(uri, projection, null, null, null);
    if (c != null && c.moveToFirst()) {
        fileName = c.getString(0);
    }
    return fileName;

}

From source file:Main.java

public static String getApnPort(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  o  m*/
        return "80";
    }

    String port = null;
    port = c.getString(c.getColumnIndex(APN_PROP_PORT));
    if (port == null) {
        c.close();
        port = "80";
    }
    c.close();
    return port;
}

From source file:Main.java

private static long getFileId(Context context, Uri fileUri) {

    Cursor cursor = context.getContentResolver().query(fileUri, mediaColumns, null, null, null);

    if (cursor.moveToFirst()) {
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
        int id = cursor.getInt(columnIndex);
        return id;
    }//  www  . j a  v a 2  s .  c  o m

    return 0;
}

From source file:Main.java

public static boolean is_any_info_available(SQLiteDatabase db) {
    boolean result = false;

    Cursor cInfo = db.rawQuery("select INFO_ID from TESTING", null);
    if (cInfo != null) {
        if (cInfo.moveToFirst()) {
            result = true;/*w  w  w.j av  a 2 s. c  om*/
        }
    }
    if (cInfo != null)
        cInfo.close();
    return result;
}

From source file:Main.java

public static Bundle getContactFromNumber(String number, Context context) {
    ContentResolver cr = context.getContentResolver();
    String[] projection = new String[] { Contacts._ID, Contacts.DISPLAY_NAME };
    Bundle bundle = new Bundle();
    Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(number));
    Cursor cursor = cr.query(contactUri, projection, null, null, null);
    try {//w ww. ja  v  a 2s . c  o  m
        if (cursor.moveToFirst()) {
            for (String key : projection) {
                bundle.putString(key, cursor.getString(cursor.getColumnIndex(key)));
            }
        }
        return bundle;
    } catch (Exception e) {
        return null;
    } finally {
        cursor.close();
    }

}

From source file:Main.java

/**
 * Get specific row values from the database,
 * e.g. all years stored in the database or
 *      all months of a year stored in the database or
 *      all days in a month of a year stored in the database
 *
 * @param db/* ww  w  .  j  av a2s  .co m*/
 *            pointer to database
 * @param requestField
 *            requested row from db
 *            "year" returns all year values found
 *            "month" returns all month values found in year <code>requestLimiterYear</code>
 *            "day" returns all day values found in month <code>requestLimiterMonth</code>
 *                                              and year <code>requestLimiterYear</code>
 * @param requestLimiterMonth
 *            limiter for request
 *            unused if requestField is "year"
 *            unused if requestField is "month"
 *            month if requestField is "day"
 * @param requestLimiterYear
 *            limiter for request
 *            unused if requestField is "year"
 *            year if requestField is "month"
 *            year if requestField is "day"
 *
 * @return <code>ArrayList<Integer></code>
 *            array list with all entries found
 */
public static ArrayList<Integer> getEntries(SQLiteDatabase db, String requestField, int requestLimiterMonth,
        int requestLimiterYear) {

    /** Array list holding the found values */
    ArrayList<Integer> returnArray = new ArrayList<>();

    /** Limiter for row search */
    String queryRequest = "select distinct " + requestField + " from " + TABLE_NAME;
    if (requestField.equalsIgnoreCase("day")) {
        queryRequest += " where month = " + String.valueOf(requestLimiterMonth) + " and year = "
                + String.valueOf(requestLimiterYear);
    } else if (requestField.equalsIgnoreCase("month")) {
        queryRequest += " where year = " + String.valueOf(requestLimiterYear);
    }

    /** Cursor holding the records of a day */
    Cursor allRows = db.rawQuery(queryRequest, null);

    allRows.moveToFirst();
    for (int i = 0; i < allRows.getCount(); i++) {
        returnArray.add(allRows.getInt(0));
        allRows.moveToNext();
    }
    allRows.close();
    return returnArray;
}

From source file:Main.java

/**
 * get the sound list of the system//from w w  w.  jav  a2s  .co m
 */
public static ArrayList<String> getSystemRingList(Context con) {
    ArrayList<String> getArray = new ArrayList<String>();
    ContentResolver cr = con.getContentResolver();
    String[] cols = new String[] { MediaStore.Audio.Media.IS_RINGTONE, MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME };
    Cursor cursor = cr.query(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, cols, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if (cursor.getString(0).equals("1")) {
                getArray.add(cursor.getString(2));
            }

        } while (cursor.moveToNext());
    }
    return getArray;
}

From source file:Main.java

public static String getRealPathFromURI(Context context, Uri contentUri) {
    String res = null;/*from   w w  w  . j av a  2 s .c  o  m*/
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor.moveToFirst()) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        res = cursor.getString(column_index);
    }
    cursor.close();
    return res;
}

From source file:Main.java

public static String getGSFID(Context context) {
    String result;//from w ww  .jav  a 2  s . c  o  m
    final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
    final String ID_KEY = "android_id";
    String[] params = { ID_KEY };
    Cursor c = context.getContentResolver().query(URI, null, null, params, null);
    if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) {
        return null;
    } else {
        result = Long.toHexString(Long.parseLong(c.getString(1)));
    }
    c.close();
    return result;
}

From source file:Main.java

public static File getFileFromUri(Uri uri, Activity activity) {
    String filePath = null;//from   ww  w  .j ava  2 s  .c om
    String scheme = uri.getScheme();
    filePath = uri.getPath();
    if (filePath != null && scheme != null && scheme.equals("file")) {
        return new File(filePath);
    }

    String[] projection = { MediaStore.Images.ImageColumns.DATA };
    Cursor c = activity.managedQuery(uri, projection, null, null, null);
    if (c != null && c.moveToFirst()) {
        filePath = c.getString(0);
    }
    if (filePath != null) {
        return new File(filePath);
    }
    return null;

}