List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static String getAbsoluteImagePath(Activity paramActivity, Uri paramUri) { Cursor localCursor = paramActivity.managedQuery(paramUri, new String[] { "_data" }, null, null, null); int i = localCursor.getColumnIndexOrThrow("_data"); localCursor.moveToFirst();// w ww.java 2 s. c o m return localCursor.getString(i); }
From source file:Main.java
public static String getImagePath(Context context, String id) { String path = null;//from w w w . j a va 2 s . c om Cursor cursor = context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, null, Media._ID + "=?", new String[] { id }, null); while (cursor.moveToNext()) { path = cursor.getString(cursor.getColumnIndex(Media.DATA)); } cursor.close(); return path; }
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { // can post image String[] proj = { Media.DATA }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(Media.DATA); cursor.moveToFirst();//from w ww . j av a2 s . c om String path = cursor.getString(column_index); cursor.close(); return path; }
From source file:Main.java
public static String getAbsoluteImagePath(Context context, Uri uri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null); cursor.moveToFirst();//from w w w . java 2s. co m int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); return cursor.getString(column_index); }
From source file:Main.java
public static String getRealPathFromURI_BelowAPI11(Context context, Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();//ww w.j a va 2 s . com return cursor.getString(column_index); }
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;//from w w w . j ava2 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 { 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;/*from w ww . j a v a2s .c om*/ 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 String getRealImagePath(Activity activity, Uri uriPath) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.getContentResolver().query(uriPath, proj, null, null, null); int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst();/*from www . j a v a2 s. com*/ String path = cursor.getString(index); // path = path.substring(5); return path; }
From source file:Main.java
public static ArrayList<String> cursorToArrayList(Cursor cursor) { ArrayList<String> list = new ArrayList<>(); if (cursor == null) return list; cursor.moveToFirst();//w w w.java2 s . co m while (!cursor.isAfterLast()) { list.add(cursor.getString(0)); cursor.moveToNext(); } return list; }
From source file:Main.java
public static List<String> displayContacts(ContentResolver contentResolver) { List<String> contacts = new ArrayList<String>(); ContentResolver cr = contentResolver; 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)); // Toast.makeText(this, "Name: " + name + ", Phone No: " + phoneNo, Toast.LENGTH_SHORT).show(); contacts.add(name + " : " + phoneNo); }//from ww w. j av a2 s.c o m pCur.close(); } } } return contacts; }