List of usage examples for android.database Cursor getString
String getString(int columnIndex);
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; }//from w w w . j a v a 2 s. c o m } pCur.close(); } } } return false; }
From source file:Main.java
/** * Get the unread count for the given shortcut info * @param c cursor holding the unread counts * @param packageName the package we are looking for * @return int of the unread count//from w w w .ja v a2 s .co m */ public static int getUnreadCount(Cursor c, String packageName) { int count = 0; try { if (c.moveToFirst()) { String currName = null; do { currName = c.getString(c.getColumnIndex("package_name")); if (currName.equals(packageName)) { count = c.getInt(c.getColumnIndex("count")); } } while (c.moveToNext()); } } catch (Exception e) { } return count; }
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();//from www . ja v a 2 s.c o m String path = cursor.getString(column_index); cursor.close(); 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();// w w w . ja va 2s . c o m return cursor.getString(columnIndex); }
From source file:Main.java
static String getFileName(Context context, Uri uri) { String result = null;//from w ww . j a v a2 s . 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:Main.java
/** * Helper method to reslove a uri into a path. * /*from w w w . ja v a 2 s . c om*/ * @param contentURI * a uri path * @return the path as a string */ public static String getRealPathFromURI(Uri contentURI, Context context) { Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); String path = cursor.getString(idx); cursor.close(); return path; }
From source file:Main.java
public static String getPath(Context context, Uri uri) throws NullPointerException { final String[] projection = { MediaColumns.DATA }; final Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null); final int column_index = cursor.getColumnIndexOrThrow(MediaColumns.DATA); cursor.moveToFirst();//from ww w .j ava 2 s .co m return cursor.getString(column_index); }
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();//from w ww.j a v a2 s.c om String path = cursor.getString(column_index); cursor.close(); return path; }
From source file:de.stadtrallye.rallyesoft.util.converters.CursorConverters.java
public static ChatEntry getChatEntry(Cursor cursor, ChatCursorIds c) { return new ChatEntry(cursor.getInt(c.id), cursor.getString(c.message), cursor.getLong(c.timestamp), cursor.getInt(c.groupID), cursor.getString(c.groupName), cursor.getInt(c.userID), cursor.getString(c.userName), cursor.getString(c.pictureHash)); }
From source file:Main.java
public static String getAbsolutePathFromUri(Context ctx, Uri contentUri) { String[] proj = { MediaStore.Video.Media.DATA }; Cursor cursor = ctx.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from w w w. j a v a 2 s .com*/ return cursor.getString(column_index); }