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:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java

/**
 * Looks for a category with a given id.
 *
 * @param context The context this is running in.
 * @param categoryId Id of the category to look for.
 * @return The found category./*from w w w .j  av a2s . co  m*/
 */
public static Category getCategoryWith(Context context, String categoryId) {
    SQLiteDatabase readableDatabase = getReadableDatabase(context);
    String[] selectionArgs = { categoryId };
    Cursor data = readableDatabase.query(CategoryTable.NAME, CategoryTable.PROJECTION,
            CategoryTable.COLUMN_ID + "=?", selectionArgs, null, null, null);
    data.moveToFirst();
    return getCategory(data, readableDatabase);
}

From source file:com.bjorsond.android.timeline.utilities.Utilities.java

public static String getRealPathFromURI(Uri contentUri, Activity a) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = a.managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

From source file:com.binomed.showtime.android.util.localisation.LocationUtils.java

private static boolean checkSkyHookRegistration(Context context) {
    boolean result = false;
    CineShowtimeDbAdapter mDbHelper = new CineShowtimeDbAdapter(context);
    mDbHelper.open();/*from   w  ww. j a  v  a 2s  .  c o  m*/
    Cursor cursorRegistration = mDbHelper.fetchSkyHookRegistration();

    if (cursorRegistration != null) {
        try {
            result = cursorRegistration.moveToFirst();
        } finally {
            cursorRegistration.close();
            if ((mDbHelper != null) && mDbHelper.isOpen()) {
                mDbHelper.close();
            }
        }
    }

    return result;
}

From source file:org.zywx.wbpalmstar.engine.EUtil.java

public static java.net.Proxy checkJavaProxy(Context context) {
    java.net.Proxy proxy = null;//from  ww w  . ja v a 2s.  co m
    if (!wifiEnable(context)) {// ??APN
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
        if (mCursor != null && mCursor.moveToFirst()) {
            String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
            int proxyPort = mCursor.getInt(mCursor.getColumnIndex("port"));
            if (proxyStr != null && proxyStr.trim().length() > 0) {
                if (0 == proxyPort) {
                    proxyPort = 80;
                }
                proxy = new java.net.Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyStr, proxyPort));
            }
            mCursor.close();
        }
    }
    return proxy;
}

From source file:org.zywx.wbpalmstar.engine.EUtil.java

public static HttpHost checkAndroidProxy(Context context) {
    HttpHost proxy = null;/*from   ww  w .  ja v  a  2 s.  c o m*/
    if (!wifiEnable(context)) {// ??APN
        Uri uri = Uri.parse("content://telephony/carriers/preferapn");
        Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
        if (mCursor != null && mCursor.moveToFirst()) {
            String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy"));
            int proxyPort = mCursor.getInt(mCursor.getColumnIndex("port"));
            if (proxyStr != null && proxyStr.trim().length() > 0) {
                if (0 == proxyPort) {
                    proxyPort = 80;
                }
                proxy = new HttpHost(proxyStr, proxyPort);
            }
            mCursor.close();
        }
    }
    return proxy;
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static Date geLastRequest(Context context, PublicScript script, String trollId) {

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Cursor cursor = database.rawQuery(SQL_LAST_REQUEST, new String[] { trollId, script.name() });
    Date result = null;/*from  ww w.j  av  a2  s . c o  m*/
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        long resultTimestamp = cursor.getLong(0);
        result = new Date(resultTimestamp);
    }

    cursor.close();
    database.close();

    String format = "Last request for category %s (script=%s) and troll=%s is: '%s'";
    String message = String.format(format, script.category, script, trollId, result);
    Log.d(TAG, message);

    return result;
}

From source file:com.onesignal.NotificationOpenedProcessor.java

private static void addChildNotifications(JSONArray dataArray, String summaryGroup, SQLiteDatabase writableDb) {
    String[] retColumn = { NotificationTable.COLUMN_NAME_FULL_DATA };
    String[] whereArgs = { summaryGroup };

    Cursor cursor = writableDb.query(NotificationTable.TABLE_NAME, retColumn,
            NotificationTable.COLUMN_NAME_GROUP_ID + " = ? AND " + // Where String
                    NotificationTable.COLUMN_NAME_DISMISSED + " = 0 AND " + NotificationTable.COLUMN_NAME_OPENED
                    + " = 0 AND " + NotificationTable.COLUMN_NAME_IS_SUMMARY + " = 0",
            whereArgs, null, null, null);

    if (cursor.getCount() > 1) {
        cursor.moveToFirst();
        do {/*from  w w w  .j a va 2  s .c o m*/
            try {
                String jsonStr = cursor
                        .getString(cursor.getColumnIndex(NotificationTable.COLUMN_NAME_FULL_DATA));
                dataArray.put(new JSONObject(jsonStr));
            } catch (Throwable t) {
                OneSignal.Log(OneSignal.LOG_LEVEL.ERROR,
                        "Could not parse JSON of sub notification in group: " + summaryGroup);
            }
        } while (cursor.moveToNext());
    }

    cursor.close();
}

From source file:com.google.samples.apps.topeka.persistence.TopekaDatabaseHelper.java

/**
 * Creates objects for quizzes according to a category id.
 *
 * @param categoryId The category to create quizzes for.
 * @param database The database containing the quizzes.
 * @return The found quizzes or an empty list if none were available.
 *///from www.j  a va2s  .  c o m
private static List<Quiz> getQuizzes(final String categoryId, SQLiteDatabase database) {
    final List<Quiz> quizzes = new ArrayList<>();
    final Cursor cursor = database.query(QuizTable.NAME, QuizTable.PROJECTION,
            QuizTable.FK_CATEGORY + " LIKE ?", new String[] { categoryId }, null, null, null);
    cursor.moveToFirst();
    do {
        quizzes.add(createQuizDueToType(cursor));
    } while (cursor.moveToNext());
    cursor.close();
    return quizzes;
}

From source file:com.gmail.nagamatu.radiko.installer.RadikoInstallerActivity.java

private static String getDeviceId(Context context) {
    String id = null;/*from w w w. j  a v  a 2 s . c  om*/
    Cursor c = context.getContentResolver().query(URI_GFS_SERVICE, null, null, new String[] { "android_id" },
            null);
    try {
        c.moveToFirst();
        id = Long.toHexString(Long.parseLong(c.getString(1)));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return id;
}

From source file:eu.e43.impeller.Utils.java

public static JSONObject findPost(Context ctx, Content.Uris uris, JSONObject object) throws JSONException {
    Cursor res = ctx.getContentResolver().query(uris.activitiesUri, new String[] { "_json" },
            "actor=? AND verb='post' AND object.id=?",
            new String[] { object.getJSONObject("author").getString("id"), object.getString("id") }, null);

    try {/*from www . j  ava2 s  .co  m*/
        if (res.getCount() > 0) {
            res.moveToFirst();
            return new JSONObject(res.getString(0));
        } else {
            return null;
        }
    } finally {
        res.close();
    }
}