Example usage for android.database Cursor getString

List of usage examples for android.database Cursor getString

Introduction

In this page you can find the example usage for android.database Cursor getString.

Prototype

String getString(int columnIndex);

Source Link

Document

Returns the value of the requested column as a String.

Usage

From source file:Main.java

public static final String getTelefone(final Context contexto, final String idContato) {
    ContentResolver cr = contexto.getContentResolver();
    Cursor phones = cr.query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + idContato, null, null);
    String numero = "";
    while (phones.moveToNext()) {
        numero = phones.getString(phones.getColumnIndex(Phone.NUMBER));
        break;//from w  ww  .jav  a  2 s  .c  om
    }
    phones.close();
    return numero;
}

From source file:Main.java

/**
 * Returns a map of ring tones registered on system. Map key is ring tone name,
 * value is ring tone uri.//from  w  ww  . j  a  v  a 2s  .c om
 *
 * @param context {@link Context} used to access system data.
 * @return Map of ring tones.
 */
public static Map<String, String> getRingtones(@NonNull Context context, int type) {
    RingtoneManager manager = new RingtoneManager(context);
    manager.setType(type);
    Cursor cursor = manager.getCursor();

    Map<String, String> map = new HashMap<>();
    while (cursor.moveToNext()) {
        String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX);
        String notificationUri = cursor.getString(RingtoneManager.URI_COLUMN_INDEX);

        map.put(notificationTitle, notificationUri);
    }

    return map;
}

From source file:Main.java

public static String CursorToJson(Cursor cursor) {
    do {/*from   www  .  j a v a2 s  . com*/
        if (!cursor.moveToNext()) {
            return "";
        }
        int i = 0;
        while (i < cursor.getCount()) {
            cursor.getString(0);
            i++;
        }
    } while (true);
}

From source file:Main.java

public static String getRealPathFromURI(Context ctx, Uri uri) {
    Cursor cursor = ctx.getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();//from   ww w.j a va  2 s .  co  m
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

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();//from  w  w  w. jav  a 2s  . c o  m
    return cursor.getString(column_index);
}

From source file:Main.java

public static String getRealPathFromURI(Uri uri, Context context) {
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();//from  w  w w . jav a2 s .  c o m
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    return cursor.getString(idx);
}

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();/*ww  w  . j a va 2  s  . c  o m*/

    return cursor.getString(column_index);
}

From source file:Main.java

/**
 * get image path by uri/*from   w  w  w .j  a  v a2  s .  c o m*/
 *
 * @param context context
 * @param uri     uri
 * @return image path
 */
public static String query(Context context, Uri uri) {
    Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null,
            null);
    cursor.moveToNext();
    String path = cursor.getString(cursor.getColumnIndex(ImageColumns.DATA));
    cursor.close();
    return path;
}

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);
    }//from  ww w. j  a va 2s.  co m
    return null;
}

From source file:Main.java

/**
 * Looks up contact name in the address book by the phone number.
 * //from   w w w .  j  a  v  a2  s  . co  m
 * @param context the Android context.
 * @param phone the phone number to look up.
 * @return a contact name.
 */
public static String lookupNameByPhone(Context context, String phone) {
    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
    String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME,
            ContactsContract.Contacts._ID };
    Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);

    try {
        while (cursor.moveToNext()) {
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

            if (name != null && name.length() > 0) {
                return name;
            }
        }
    } finally {
        cursor.close();
    }

    return phone;
}