List of usage examples for android.database Cursor getColumnIndex
int getColumnIndex(String columnName);
From source file:Main.java
public static boolean hasContact(Context mContext, String contact) { ContentResolver cr = mContext.getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cur.getCount() > 0) { while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); if (Integer.parseInt( cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null); while (pCur.moveToNext()) { String phoneNo = pCur .getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); if (phoneNo.contains(contact) || contact.contains(phoneNo)) { return true; }/*w ww .ja v a 2 s . c o m*/ } pCur.close(); } } } return false; }
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 a2s . 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 { 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;/*w w w. jav a2 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; }
From source file:Main.java
public static int getApnPortInt(Context context) { Cursor c = context.getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); c.moveToFirst();//from w w w . j a va 2s.c o m if (c.isAfterLast()) { c.close(); return -1; } int result = c.getInt(c.getColumnIndex(APN_PROP_PORT)); return result; }
From source file:Main.java
/** * Get path of image from uri/*from w w w . j ava 2 s .co m*/ * * @param contentResolver * @param contentURI * @return path of image. Null if not found. */ public static String getRealImagePathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Images.ImageColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
/** * Get path of video from uri//www . j av a 2s. c o m * * @param contentResolver * @param contentURI * @return path of video. Null if not found. */ public static String getRealVideoPathFromURI(ContentResolver contentResolver, Uri contentURI) { Cursor cursor = contentResolver.query(contentURI, null, null, null, null); if (cursor == null) return contentURI.getPath(); else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(Video.VideoColumns.DATA); try { return cursor.getString(idx); } catch (Exception exception) { return null; } } }
From source file:Main.java
static String getFileName(Context context, Uri uri) { String result = null;/* www . j a v a 2s . 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)); } } 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:com.xfinity.ceylon_steel.controller.CustomerController.java
public static ArrayList<Customer> getCustomers(Context context) { ArrayList<Customer> customers = new ArrayList<Customer>(); SQLiteDatabaseHelper databaseInstance = SQLiteDatabaseHelper.getDatabaseInstance(context); SQLiteDatabase database = databaseInstance.getWritableDatabase(); Cursor customerCursor = database.rawQuery("select customerId, customerName from tbl_customer", null); int customerIdIndex = customerCursor.getColumnIndex("customerId"); int customerNameIndex = customerCursor.getColumnIndex("customerName"); for (customerCursor.moveToFirst(); !customerCursor.isAfterLast(); customerCursor.moveToNext()) { Customer customer = new Customer(customerCursor.getInt(customerIdIndex), customerCursor.getString(customerNameIndex)); customers.add(customer);//from w ww. ja v a 2 s .com } customerCursor.close(); databaseInstance.close(); return customers; }
From source file:Main.java
/** * @param mContext/*from www . j av a2s . c om*/ * @param number * @return sunrise.l String 2012-5-28 */ public static String getNameFormNumber(Context mContext, String number) { String name = null; Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, number); Cursor cur = mContext.getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cur != null && cur.moveToFirst()) { int nameIndex = cur.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME); name = cur.getString(nameIndex); } cur.close(); return name; }
From source file:Main.java
/** * This method to get real path from uri. * /*from w w w. j av a 2 s.c o m*/ * @param context * @param contentURI * @return imagepath */ public static String getRealPathFromURI(Context context, Uri contentURI) { Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { return contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); return cursor.getString(idx); } }