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

static int getCardId(Context context) {
    ContentResolver res = context.getContentResolver();
    Cursor c = res.query(Uri.parse("content://media/external/fs_id"), null, null, null, null);
    int id = -1;//from w  w  w  . j a va2s .c  o m
    if (c != null) {
        c.moveToFirst();
        id = c.getInt(0);
        c.close();
    }
    return id;
}

From source file:Main.java

public static String uriToFilePath(Activity context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor actualimagecursor = context.managedQuery(uri, proj, null, null, null);
    int actualImageColumnIndex = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    actualimagecursor.moveToFirst();
    String imgPath = actualimagecursor.getString(actualImageColumnIndex);
    return imgPath;
}

From source file:Main.java

/**
 * Finding contact name by telephone number.
 *
 * @param context Context//ww w .  ja  v  a 2 s  .  c o m
 * @param number  Telephone number
 * @return Contact display name
 */
public static String getContactName(Context context, String number) {
    Log.d(TAG, "Searching contact with number: " + number);

    /* define the columns I want the query to return */
    String[] projection = new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME };

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

    /* query time */
    Log.d(TAG, "Sending query");
    Cursor cursor = context.getContentResolver().query(contactUri, projection, null, null, null);

    String name = null;
    if (cursor.moveToFirst()) {
        /* Get values from contacts database: */
        name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
        Log.d(TAG, "Contact found for number: " + number + ". The name is: " + name);
    } else {
        Log.d(TAG, "Contact not found for number: " + number);
    }

    return name;
}

From source file:Main.java

public static String getPathFromUrl(Activity context, Uri uri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor actualimagecursor = context.managedQuery(uri, proj, null, null, null);
    int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    actualimagecursor.moveToFirst();
    String img_path = actualimagecursor.getString(actual_image_column_index);
    return img_path;
}

From source file:net.niyonkuru.koodroid.html.SubscribersHandler.java

private static boolean subscriberExists(Uri uri, ContentResolver resolver) {
    Cursor cursor = resolver.query(uri, null, null, null, null);
    try {//from  w  ww . java2s .  c o  m
        return cursor.moveToFirst();
    } finally {
        cursor.close();
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    String result = null;//from   ww w  .  j  av a 2s  .  c  o m

    CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    if (cursor != null) {
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(column_index);
    }
    return result;
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPathFromUriApi11to18(Context context, Uri contentUri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    String result = null;/*from w  ww. ja va 2s.  co  m*/

    CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null);
    Cursor cursor = cursorLoader.loadInBackground();

    if (cursor != null) {
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        result = cursor.getString(columnIndex);
    }
    return result;
}

From source file:Main.java

public static String getMmsAddress(Context context, long messageId) {
    final String[] projection = new String[] { "address", "contact_id", "charset", "type" };
    final String selection = "type=137"; // "type="+ PduHeaders.FROM,

    Uri.Builder builder = MMS_CONTENT_URI.buildUpon();
    builder.appendPath(String.valueOf(messageId)).appendPath("addr");

    Cursor cursor = context.getContentResolver().query(builder.build(), projection, selection, null, null);

    if (cursor != null) {
        try {/*from   w  w w  .  jav  a2 s. co  m*/
            if (cursor.moveToFirst()) {
                return cursor.getString(0);
            }
        } finally {
            cursor.close();
        }
    }

    return context.getString(android.R.string.unknownName);
}

From source file:Main.java

public static int getMaxSize(Context context) {
    // Note that this URI is safe to call on the UI thread.
    Cursor c = context.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
            new String[] { DisplayPhoto.DISPLAY_MAX_DIM }, null, null, null);
    try {//  ww  w  . ja  v a  2s.  co m
        c.moveToFirst();
        return c.getInt(0);
    } finally {
        c.close();
    }
}

From source file:Main.java

public static int getOrientation(Context context, Uri contentUri) {
    Cursor cursor = context.getContentResolver().query(contentUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    try {//from   ww  w .  j av  a 2s . c  o  m
        if (cursor.moveToFirst()) {
            return cursor.getInt(0);
        } else {
            return -1;
        }
    } finally {
        cursor.close();
    }
}