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:fr.mixit.android.io.RemoteSessionsHandler.java

private static boolean isSessionUpdated(Uri uri, JSONObject session, ContentResolver resolver)
        throws JSONException {
    final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null);
    try {//  w ww.j  a  v  a2 s.  co  m
        if (!cursor.moveToFirst())
            return false;

        final String curTitle = cursor.getString(SessionsQuery.TITLE).toLowerCase().trim();
        final String curSummary = cursor.getString(SessionsQuery.SUMMARY).toLowerCase().trim();
        final String curTrackId = cursor.getString(SessionsQuery.TRACK_ID) != null
                ? cursor.getString(SessionsQuery.TRACK_ID).toLowerCase().trim()
                : "";
        final String newTitle = session.getString("name").toLowerCase().trim();
        final String newSummary = session.getString("description").toLowerCase().trim();
        final String newTrackId = session.has("track") ? session.getString("track").toLowerCase().trim() : "";

        return (!curTitle.equals(newTitle) || !curSummary.equals(newSummary) || !curTrackId.equals(newTrackId));
    } finally {
        cursor.close();
    }
}

From source file:com.docd.purefm.test.MediaStoreUtilsTest.java

private static boolean isFileInMediaStore(final ContentResolver resolver, final GenericFile file) {
    final Uri uri = MediaStoreUtils.getContentUri(file);
    final Pair<String, String[]> selection = MediaStoreUtils.dataSelection(file.toFile());
    final Cursor c = resolver.query(uri, new String[] { MediaStore.Files.FileColumns._ID }, selection.first,
            selection.second, null);//from w w w . j a  va  2  s. c o m
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                return c.getLong(0) != 0;
            }
        } finally {
            c.close();
        }
    }
    return false;
}

From source file:Main.java

private static int getOrientation(Context context, Uri photoUri) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor.getCount() != 1) {
        return -1;
    }/*from   w ww.ja  v a 2  s. c om*/

    cursor.moveToFirst();
    return cursor.getInt(0);
}

From source file:com.dahl.brendan.wordsearch.view.IOService.java

private static void writeFile(Context context, File file, boolean overwrite) {
    if (!file.exists() || overwrite) {
        Cursor cursor = context.getContentResolver().query(Word.CONTENT_URI, new String[] { Word.WORD }, null,
                null, null);/*from   w  w w  .  j  a v  a  2  s  . c  om*/
        JSONArray array = new JSONArray();
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                array.put(cursor.getString(0));
                cursor.moveToNext();
            }
        }
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            out.write(array.toString());
            out.close();
        } catch (IOException e) {
            Log.e(LOGTAG, "write failed", e);
        }
    }
}

From source file:Main.java

public static String getPersonNameFromNumber(Context context, String box, String address) {
    if (address == null) {
        return "unknown";
    }/* w w w . j a va  2s.  co  m*/
    if (!box.equalsIgnoreCase("draft")) {
        Cursor cursor = context.getContentResolver().query(
                Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)),
                new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
        if (cursor != null) {
            try {
                if (cursor.getCount() > 0) {
                    cursor.moveToFirst();
                    String name = cursor.getString(0);
                    return name;
                }
            } finally {
                cursor.close();
            }
        }
    }
    if (address != null) {
        return PhoneNumberUtils.formatNumber(address);
    }
    return "unknown";
}

From source file:Main.java

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context./*from   w ww  .j  av  a  2s  .c o m*/
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

From source file:Main.java

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context./*from w  ww .  j  a va2 s .co m*/
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {

        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {

            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {

        if (cursor != null) {
            cursor.close();
        }
    }
    return null;
}

From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java

public static Cursor queryAccountsForProvider(ContentResolver cr, String[] projection, long providerId) {
    StringBuilder where = new StringBuilder(Imps.Account.ACTIVE);
    where.append("=1 AND ").append(Imps.Account.PROVIDER).append('=').append(providerId);
    Cursor c = cr.query(Imps.Account.CONTENT_URI, projection, where.toString(), null, null);
    if (c != null && !c.moveToFirst()) {
        c.close();//www .j ava2  s.c o  m
        return null;
    }
    return c;
}

From source file:Main.java

/**
 * Get the value of the data column for this Uri . This is useful for
 * MediaStore Uris , and other file - based ContentProviders.
 * /*  w  w  w.ja v  a 2s  .  com*/
 * @param context
 *            The context.
 * @param uri
 *            The Uri to query.
 * @param selection
 *            (Optional) Filter used in the query.
 * @param selectionArgs
 *            (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = MediaColumns.DATA;
    final String[] projection = { column };
    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

From source file:Main.java

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context       The context./*  w  w  w. java2s  . c  o  m*/
 * @param uri           The Uri to query.
 * @param selection     (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}