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 boolean hasShortcut(Context cx) {
    boolean result = false;
    String title = null;//www  . ja v a2  s. com
    try {
        final PackageManager pm = cx.getPackageManager();
        title = pm.getApplicationLabel(pm.getApplicationInfo(cx.getPackageName(), PackageManager.GET_META_DATA))
                .toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    final String AUTHORITY;
    if (android.os.Build.VERSION.SDK_INT < 8) {
        AUTHORITY = "com.android.launcher.settings";
    } else {
        AUTHORITY = "com.android.launcher2.settings";
    }
    final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
    final Cursor c = cx.getContentResolver().query(CONTENT_URI, null, "title=?", new String[] { title }, null);
    if (c != null && c.moveToFirst()) {
        c.close();
        result = true;
    }
    return result;
}

From source file:org.hfoss.posit.android.web.PositHttpUtils.java

public static List<NameValuePair> convertFindsForPost(String[] projection, Cursor c) {
    List<NameValuePair> finds = new ArrayList<NameValuePair>();
    c.moveToFirst();
    try {/*from   www. j  a va2  s  . co m*/
        for (String item : projection) {
            finds.add(new BasicNameValuePair(item, c.getString(c.getColumnIndexOrThrow(item))));
        }
    } catch (CursorIndexOutOfBoundsException e) {
        if (Utils.debug)
            Log.e(TAG, e.getMessage());
    }
    return finds;
}

From source file:Main.java

static String getFileName(Context context, Uri uri) {
    String result = null;//from www .j  av  a 2s . com
    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));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    if (result == null) {
        result = uri.getPath();
        int cut = result.lastIndexOf(File.separator);
        if (cut != -1) {
            result = result.substring(cut + 1);
        }
    }
    return result;
}

From source file:Main.java

public static String getRealImagePath(Activity activity, Uri uriPath) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = activity.getContentResolver().query(uriPath, proj, null, null, null);
    int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(index);
    // path = path.substring(5);
    return path;/* ww  w. ja va2s.co m*/
}

From source file:Main.java

public static String convertMediaUriToPath(Context context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index);
    cursor.close();/*from   w w w  .j a va  2  s  .c  om*/
    return path;
}

From source file:disono.webmons.com.utilities.helpers.WBFile.java

/**
 * Get the real path from URI//from  w w w.  j  a v  a 2  s  .  c  o  m
 *
 * @param activity
 * @param uri
 * @return
 */
public static String getRealPathFromURI(Activity activity, Uri uri) {
    Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
    assert cursor != null;
    cursor.moveToFirst();
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

From source file:Main.java

public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, 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

public static String getContactName(Context context, String number) {

    String name = null;//from   ww w  .  j  a  va 2s .  co  m

    // define the columns I want the query to return
    String[] projection = new String[] { Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            ? ContactsContract.Contacts.DISPLAY_NAME_PRIMARY
            : ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.PhoneLookup._ID };

    // encode the phone number and build the filter URI
    Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    // query time
    Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);

    if (cursor != null) {
        if (cursor.moveToFirst()) {
            name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
            Log.v("getContactName", "Started uploadcontactphoto: Contact Found @ " + number);
            Log.v("getContactName", "Started uploadcontactphoto: Contact name  = " + name);
        } else {
            Log.v("getContactName", "Contact Not Found @ " + number);
        }
        cursor.close();
    }
    return name;
}

From source file:Main.java

public static String getPath(Context context, Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    String path = cursor.getString(column_index);
    cursor.close();/*from w w w.j a va 2  s. c o m*/
    return path;
}

From source file:Main.java

public static String getRealPathFromUriBelowApi11(Context context, Uri contentUri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = context.getContentResolver().query(contentUri, projection, null, null, null);
    int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(columnIndex);
}