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.RemoteSpeakersHandler.java

private static boolean isSpeakerUpdated(Uri uri, JSONObject speaker, ContentResolver resolver)
        throws JSONException {
    final Cursor cursor = resolver.query(uri, SpeakersQuery.PROJECTION, null, null, null);
    try {//  ww w.j  a v  a  2 s.  c  o m
        if (!cursor.moveToFirst())
            return false;

        final String curFirstName = cursor.getString(SpeakersQuery.FIRST_NAME).toLowerCase().trim();
        final String curLastName = cursor.getString(SpeakersQuery.LAST_NAME).toLowerCase().trim();
        final String curBio = cursor.getString(SpeakersQuery.BIO).toLowerCase().trim();
        final String curCompany = cursor.getString(SpeakersQuery.COMPANY).toLowerCase().trim();
        final String curLinkedIn = cursor.getString(SpeakersQuery.LINKEDIN).toLowerCase().trim();
        final String curTwitter = cursor.getString(SpeakersQuery.TWITTER).toLowerCase().trim();
        final String curBlog = cursor.getString(SpeakersQuery.BLOG).toLowerCase().trim();
        final String newFirstName = speaker.has("firstName")
                ? speaker.getString("firstName").toLowerCase().trim()
                : curFirstName;
        final String newLastName = speaker.has("lastName") ? speaker.getString("lastName").toLowerCase().trim()
                : curLastName;
        final String newBio = speaker.has("bio") ? speaker.getString("bio").toLowerCase().trim() : curBio;
        final String newCompany = speaker.has("company") ? speaker.getString("company").toLowerCase().trim()
                : curCompany;
        final String newLinkedIn = speaker.has("linkedin") ? speaker.getString("linkedin").toLowerCase().trim()
                : curLinkedIn;
        final String newTwitter = speaker.has("twitter") ? speaker.getString("twitter").toLowerCase().trim()
                : curTwitter;
        final String newBlog = speaker.has("blog") ? speaker.getString("blog").toLowerCase().trim() : curBlog;

        return (!curFirstName.equals(newFirstName) || !curLastName.equals(newLastName) || !curBio.equals(newBio)
                || !curCompany.equals(newCompany) || !curLinkedIn.equals(newLinkedIn)
                || !curTwitter.equals(newTwitter) || !curBlog.equals(newBlog));
    } finally {
        cursor.close();
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPathFromURI_API19(Context context, Uri uri) {
    String filePath = "";
    if (DocumentsContract.isDocumentUri(context, uri)) {
        String wholeID = DocumentsContract.getDocumentId(uri);
        // Split at colon, use second item in the array
        String[] splits = wholeID.split(":");
        if (splits.length == 2) {
            String id = splits[1];

            String[] column = { MediaStore.Images.Media.DATA };
            // where id is equal to
            String sel = MediaStore.Images.Media._ID + "=?";
            Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    column, sel, new String[] { id }, null);
            int columnIndex = cursor.getColumnIndex(column[0]);
            if (cursor.moveToFirst()) {
                filePath = cursor.getString(columnIndex);
            }//w w w. j  a va  2 s.c o m
            cursor.close();
        }
    } else {
        filePath = uri.getPath();
    }
    return filePath;
}

From source file:Main.java

public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String column = MediaStore.Images.Media.DATA;
    String[] projection = { column };
    try {/*from   ww  w. j  a va  2 s .  co m*/
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}

From source file:Main.java

public static String getDataColumn(final Context context, final Uri uri, final String selection,
        final String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = { column };

    try {//from w  w  w. jav  a  2  s.c o  m
        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

@Nullable
public static File getFromMediaUri(Context context, ContentResolver resolver, Uri uri) {
    if (uri == null)
        return null;

    if (SCHEME_FILE.equals(uri.getScheme())) {
        return new File(uri.getPath());
    } else if (SCHEME_CONTENT.equals(uri.getScheme())) {
        final String[] filePathColumn = { MediaStore.MediaColumns.DATA, MediaStore.MediaColumns.DISPLAY_NAME };
        Cursor cursor = null;
        try {//from  w w  w.j ava2 s . c  o m
            cursor = resolver.query(uri, filePathColumn, null, null, null);
            if (cursor != null && cursor.moveToFirst()) {
                final int columnIndex = (uri.toString().startsWith("content://com.google.android.gallery3d"))
                        ? cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)
                        : cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
                // Picasa images on API 13+
                if (columnIndex != -1) {
                    String filePath = cursor.getString(columnIndex);
                    if (!TextUtils.isEmpty(filePath)) {
                        return new File(filePath);
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            // Google Drive images
            return getFromMediaUriPfd(context, resolver, uri);
        } catch (SecurityException ignored) {
            // Nothing we can do
        } finally {
            if (cursor != null)
                cursor.close();
        }
    }
    return null;
}

From source file:Main.java

private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String column = MediaStore.Images.Media.DATA;
    String[] projection = { column };
    try {//from   ww w.j a  v  a2s .c  o  m
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            int index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(index);
        }
    } finally {
        if (cursor != null && !cursor.isClosed())
            cursor.close();
    }
    return null;
}

From source file:Main.java

private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    String column = MediaStore.Images.Media.DATA;
    String[] projection = { column };
    try {/*from   w w w. j a va2s  .  c o  m*/
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            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./*from ww w .ja v a2 s . 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;
}

From source file:Main.java

public static boolean isMediaScannerScanning(Context context) {
    boolean result = false;
    Cursor cursor = query(context, MediaStore.getMediaScannerUri(),
            new String[] { MediaStore.MEDIA_SCANNER_VOLUME }, null, null, null);
    if (cursor != null) {
        if (cursor.getCount() == 1) {
            cursor.moveToFirst();
            result = "external".equals(cursor.getString(0));
        }//from  w w w.  j ava2  s  .  c  o m
        cursor.close();
    }

    return result;
}

From source file:Main.java

public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {

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

    try {//from   www. ja  v a2 s.c om
        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);
        }
    } catch (Exception e) {
        Log.d("android_utilities", "the error is " + e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return null;
}