Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:Main.java

static int getCardId(Context context) {
    ContentResolver res = context.getContentResolver();
    Cursor c = res.query(Uri.parse("content://media/external/fs_id"), null, null, null, null);
    int id = -1;/*  w  w  w  .j av a 2 s  . co  m*/
    if (c != null) {
        c.moveToFirst();
        id = c.getInt(0);
        c.close();
    }
    return id;
}

From source file:Main.java

public static int findPrimaryKey(SQLiteDatabase db, String tableName, String address) {
    int key = -1;
    Cursor cursor = db.query(tableName, new String[] { "DQXX01" }, "DQXX05=?", new String[] { address }, null,
            null, null);/* w w w  .j  ava 2 s .  c o m*/
    if (cursor != null) {
        if (cursor.moveToNext()) {
            key = cursor.getInt(0);
        }
    }
    return key;
}

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// w w  w  .  j a v a 2s .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

public static int findPrimaryKey(SQLiteDatabase db, String address) {
    int key = -1;
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01" }, "DQXX05=?", new String[] { address }, null,
            null, null);/*  ww  w  .j a v  a  2s . c om*/
    if (cursor != null) {
        if (cursor.moveToNext()) {
            key = cursor.getInt(0);
        }
    }
    return key;
}

From source file:Main.java

public static int getSmsCount(Context context) {
    try {/*from   w w  w.  ja  v  a  2s  . com*/
        int result = 0;
        Cursor c = context.getContentResolver().query(Uri.parse("content://sms/inbox"),
                new String[] { "count(_id)", }, null, null, null);
        if (c.moveToFirst()) {
            result = c.getInt(0);
        }
        c.close();
        return result;
    } catch (Throwable t) {
        LOGE("getSmsCount: " + t.getMessage());
        t.printStackTrace();
    }
    return 0;
}

From source file:Main.java

public static int getMaxSize(Context context) {
    // Note that this URI is safe to call on the UI thread.
    Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
            new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null);
    try {//w w  w.j  av  a2  s. c  o m
        c.moveToFirst();
        return c.getInt(0);
    } finally {
        c.close();
    }
}

From source file:Main.java

public static int getImageIdFromPath(Activity activity, String filePath) {
    String[] projection = { MediaStore.Images.Media._ID };
    Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    String where = String.format("_data like '%s' ", filePath);
    Cursor cursor = MediaStore.Images.Media.query(activity.getContentResolver(), uri, projection, where, null);
    int image_id = 0;
    if (cursor.getCount() != 0) {
        cursor.moveToFirst();//from  w ww  . j  a v  a  2  s. com
        image_id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
        cursor.close();
    }
    return image_id;
}

From source file:Main.java

public static int getOrientation(Context context, Uri contentUri) {
    Cursor cursor = context.getContentResolver().query(contentUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    try {//from www . j  a v a 2s.  c o  m
        if (cursor.moveToFirst()) {
            return cursor.getInt(0);
        } else {
            return -1;
        }
    } finally {
        cursor.close();
    }
}

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;
    }//w  w w .ja  v a2 s. c  om

    return 0;
}

From source file:Main.java

/**
 * Tries to find out if the given cursor points to a dataset with unread articles in it, returns true if it does.
 *
 * @param cursor the cursor./*from  w  w w .j  a v  a2  s .  c o  m*/
 * @return true if there are unread articles in the dataset, else false.
 */
private static boolean checkUnread(Cursor cursor) {
    if (cursor == null || cursor.isClosed())
        return false; // Check null or closed

    if (!cursor.moveToFirst())
        return false; // Check empty

    do {
        if (cursor.getInt(cursor.getColumnIndex("unread")) > 0)
            return cursor.moveToFirst(); // One unread article found, move to first entry
    } while (cursor.moveToNext());

    cursor.moveToFirst();
    return false;
}