List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:Main.java
public static Map<String, Uri> getRingtones(Activity activity) { RingtoneManager manager = new RingtoneManager(activity); manager.setType(RingtoneManager.TYPE_RINGTONE); Cursor cursor = manager.getCursor(); Map<String, Uri> list = new LinkedHashMap<>(); while (cursor.moveToNext()) { String notificationTitle = cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX); Uri notificationUri = manager.getRingtoneUri(cursor.getPosition()); list.put(notificationTitle, notificationUri); }// w w w .j a v a 2 s .c o m return list; }
From source file:Main.java
public static String query(Context context, Uri uri) { Cursor cursor = context.getContentResolver().query(uri, new String[] { ImageColumns.DATA }, null, null, null);/*from w ww .jav a 2 s. c o m*/ cursor.moveToNext(); return cursor.getString(cursor.getColumnIndex(ImageColumns.DATA)); }
From source file:Main.java
public static String query(Context context, Uri uri) { Cursor cursor = context.getContentResolver().query(uri, new String[] { MediaColumns.DATA }, null, null, null);//from w ww.ja v a 2s. c o m cursor.moveToNext(); return cursor.getString(cursor.getColumnIndex(MediaColumns.DATA)); }
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 www. j av a 2 s . co m * * @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
/** * get the connection proxy and port// w w w . j av a 2s .c o m * @param context * @return */ public static String[] getHostAndProxy(Context context) { Uri uri = Uri.parse("content://telephony/carriers/preferapn"); Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null); if (mCursor != null) { mCursor.moveToNext(); String proxyStr = mCursor.getString(mCursor.getColumnIndex("proxy")); String port = mCursor.getString(mCursor.getColumnIndex("port")); return new String[] { proxyStr, port }; } return null; }
From source file:Main.java
public static boolean isCityExist(Context context, String city) { File file = new File(context.getFilesDir(), DATABASE_NAME); SQLiteDatabase db = context.openOrCreateDatabase(file.getAbsolutePath(), Context.MODE_PRIVATE, null); Cursor cursor = db.rawQuery("select count(1) from " + TABLE_NAME + " where DQXX02=?", new String[] { city }); cursor.moveToNext(); return cursor.getInt(0) > 0; }
From source file:Main.java
public static long[] readIds(Cursor cursor) { long[] arr = new long[cursor.getCount()]; int count = 0; try {/*from w ww. j a v a 2 s . c o m*/ while (cursor.moveToNext()) { arr[count++] = cursor.getLong(0); } } finally { cursor.close(); } return arr; }
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;// w ww. j a v a 2 s . c om } phones.close(); return numero; }
From source file:Main.java
public static List<String[]> multiRecordToArray(Cursor cursor) { ArrayList<String[]> result = new ArrayList<String[]>(); try {//from ww w . jav a2s. co m while (cursor.moveToNext()) { String[] record = new String[cursor.getColumnCount()]; fillArray(cursor, record); result.add(record); } } finally { closeQuietly(cursor); } return result; }
From source file:Main.java
/** * Looks up contact name in the address book by the phone number. * /*from ww w .ja v a 2s. c o 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; }