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 int getRotationFromUri(Context context, Uri imageUri) {
    String[] orientationColumn = { MediaStore.Images.Media.ORIENTATION };
    Cursor cur = context.getContentResolver().query(imageUri, orientationColumn, null, null, null);
    int orientation = -1;
    if (cur != null && cur.moveToFirst()) {
        orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
    }/*from   w w w .  j  a  v  a  2  s  .  co m*/

    return orientation;
}

From source file:Main.java

public static String getImageAbsolutePath(Context context, Uri uri) {
    Cursor cursor = MediaStore.Images.Media.query(context.getContentResolver(), uri,
            new String[] { MediaStore.Images.Media.DATA });
    if (cursor.moveToFirst()) {
        return cursor.getString(0);
    }/* w  w w  . j  a v a  2 s . c o m*/
    return null;
}

From source file:Main.java

private static String getImageAbsolutePath0(Activity act, Uri uri) {
    // can post image
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = act.managedQuery(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();

    return cursor.getString(column_index);
}

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.//w w w .j a v  a  2s. com
 * @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;
}

From source file:Main.java

/** converts image content URI to file path */
public static String resolveUri(Activity activity, Uri uri) {
    String[] projection = { Images.Media.DATA };
    Cursor cursor = activity.managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

From source file:Main.java

/**
 * Converts the content:// scheme to the file path
 * @param contentResolver Provides access to the content model
 * @param contentUri The URI to be converted using content:// scheme
 * @return The converted file path//from  w w w  . ja va  2  s .  c o m
 */
public static String getPathFromContentUri(ContentResolver contentResolver, Uri contentUri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = contentResolver.query(contentUri, projection, null, null, null);

    if (cursor != null && cursor.moveToFirst()) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        String filePath = cursor.getString(column_index);
        cursor.close();
        return filePath;
    } else {
        return null;
    }
}

From source file:Main.java

public static String getAbsoluteImagePath(Context context, Uri uri) {
    // can post image
    String[] proj = { Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index);
    cursor.close();//from   w w  w.  j a va2  s  . c  o  m
    return path;
}

From source file:Main.java

public static String getAbsoluteImagePath(Activity paramActivity, Uri paramUri) {
    Cursor localCursor = paramActivity.managedQuery(paramUri, new String[] { "_data" }, null, null, null);
    int i = localCursor.getColumnIndexOrThrow("_data");
    localCursor.moveToFirst();
    return localCursor.getString(i);
}

From source file:Main.java

private static String getFileName(Context context, Uri uri) {
    Log.d("suka", uri.getScheme() + " : " + context.getContentResolver().getType(uri));
    String result = null;/* w  ww .  j  av a  2  s  .c o m*/
    if (uri.getScheme().equals("content")) {
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            }
        } finally {
            cursor.close();
        }
    }
    if (result == null) {
        Log.d("suka", "res " + uri.getPath());
        result = uri.getPath();
        int cut = result.lastIndexOf('/');
        if (cut != -1) {
            result = result.substring(cut + 1);
        }
    }
    return result;
}

From source file:Main.java

public static String getFileName(Uri uri, Context context) {
    String result = null;//from   w ww .  j  a  va2 s  .co  m
    if (uri.getScheme().equals("content")) {
        Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    if (result == null) {
        result = uri.getPath();
        int cut = result.lastIndexOf('/');
        if (cut != -1) {
            result = result.substring(cut + 1);
        }
    }
    return result;
}