List of usage examples for android.database Cursor getString
String getString(int columnIndex);
From source file:Main.java
public static String queryAudioName(Context context, Uri name) { String audioId;/* w ww.j a v a2 s . com*/ String uriName = name.toString(); uriName = uriName.substring(uriName.lastIndexOf("/") + 1); Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); int counter = cursor.getCount(); for (int j = 0; j < counter; j++) { audioId = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media._ID)); if (uriName.equals(audioId)) { uriName = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE)); } else { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); break; } cursor.moveToNext(); } cursor.close(); } else { try { Ringtone ringtone = RingtoneManager.getRingtone(context, name); uriName = ringtone.getTitle(context); } catch (Exception e) { return uriName; } } return uriName; }
From source file:Main.java
public static String getPersonNameFromNumber(Context context, String box, String address) { if (address == null) { return "unknown"; }//from w ww . j a v a2 s. c o m if (!box.equalsIgnoreCase("draft")) { Cursor cursor = context.getContentResolver().query( Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)), new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); return name; } } finally { cursor.close(); } } } if (address != null) { return PhoneNumberUtils.formatNumber(address); } return "unknown"; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *///from ww w.j av a 2 s .c o m public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:Main.java
/** * Get the real file path from URI registered in media store * @param contentUri URI registered in media store *//* w w w. j a v a2 s . c o m*/ @SuppressWarnings("deprecation") public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS, JB Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; CursorLoader cursorLoader = new CursorLoader(activity, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { // URI from Gallery(MediaStore) String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); cursor.close(); } // URI from Others(Dropbox, etc.) if (strFileName == null || strFileName.isEmpty()) { if (contentUri.getScheme().compareTo("file") == 0) strFileName = contentUri.getPath(); } return strFileName; } } //--------------------- // Undefined Version //--------------------- /* GB, ICS Common */ String[] proj = { MediaStore.Images.Media.DATA }; String strFileName = ""; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); // Use the Cursor manager in ICS activity.startManagingCursor(cursor); cursor.moveToFirst(); if (cursor.getCount() > 0) strFileName = cursor.getString(column_index); //cursor.close(); // If the cursor close use , This application is terminated .(In ICS Version) activity.stopManagingCursor(cursor); } return strFileName; }
From source file:Main.java
public static String uriTitle(Context context, String contentUri) { String result = null;/*w w w .ja va 2s. c o m*/ String[] p = { MediaStore.MediaColumns.TITLE }; Uri uri = Uri.parse(contentUri); if (!uri.getScheme().equals("content")) { return (fileUriTitle(context, contentUri)); } Cursor cursor = context.getContentResolver().query(uri, p, // which columns null, // which rows (all rows) null, // selection args (none) null); // order-by clause (ascending by name) if (cursor != null) { int iColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE); if (cursor.moveToFirst()) { result = cursor.getString(iColumn); } } return (result); }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * @param c a cursor pointing at an item's row * @return true if the item is editable by the logged-in user. *///from w ww . j av a2s.c o m public static boolean canEdit(Context context, Cursor c) { final String privacy = c.getString(c.getColumnIndex(_PRIVACY)); final String useruri = Authenticator.getUserUri(context); return privacy == null || useruri == null || useruri.length() == 0 || useruri.equals(c.getString(c.getColumnIndex(_AUTHOR_URI))); }
From source file:Main.java
public static String getRealPathFromURI(Context context, Uri contentURI) { String TAG = "PINGUINO-getRealPathFromURI"; String result;/* ww w . ja v a 2 s. c o m*/ Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { result = contentURI.getPath(); } else { Log.d(TAG, "cursor1:" + cursor); cursor.moveToFirst(); Log.d(TAG, "cursor2:" + cursor); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); Log.d(TAG, "idx:" + idx); result = cursor.getString(idx); Log.d(TAG, "result:" + result); cursor.close(); } return result; }
From source file:Main.java
public static Cursor getAllCallLogAboutACaller(Context context, String callerNumber) { // cancello la chiamata in uscita se nelle preferenze ? settata tale opzione Uri delUri = Uri.withAppendedPath(CallLog.Calls.CONTENT_URI, ""); Cursor cursor = context.getContentResolver().query(delUri, null, android.provider.CallLog.Calls.NUMBER + "=?", new String[] { "404" }, null); try {//from w ww. ja v a 2 s . c o m boolean moveToFirst = cursor.moveToFirst(); Log.i("MOVETOFIRST", "moveToFirst=" + moveToFirst); do { int numberColumn = cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER); String callerPhoneNumber = cursor.getString(numberColumn); Log.i(TAG, "numero : " + callerPhoneNumber); } while (cursor.moveToNext()); } catch (Exception e) { Log.e(TAG, "Problem moving to first entry", e); } return cursor; }
From source file:fr.mixit.android.io.RemoteSessionsHandler.java
private static boolean isSessionUpdated(Uri uri, JSONObject session, ContentResolver resolver) throws JSONException { final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null); try {//from w w w .java 2 s.c o m if (!cursor.moveToFirst()) return false; final String curTitle = cursor.getString(SessionsQuery.TITLE).toLowerCase().trim(); final String curSummary = cursor.getString(SessionsQuery.SUMMARY).toLowerCase().trim(); final String curTrackId = cursor.getString(SessionsQuery.TRACK_ID) != null ? cursor.getString(SessionsQuery.TRACK_ID).toLowerCase().trim() : ""; final String newTitle = session.getString("name").toLowerCase().trim(); final String newSummary = session.getString("description").toLowerCase().trim(); final String newTrackId = session.has("track") ? session.getString("track").toLowerCase().trim() : ""; return (!curTitle.equals(newTitle) || !curSummary.equals(newSummary) || !curTrackId.equals(newTrackId)); } finally { cursor.close(); } }
From source file:Main.java
public static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) { Cursor cursor = null; final String column = "_data"; final String[] projection = { column }; try {//from w w w. java2s . com cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null); if (cursor != null && cursor.moveToFirst()) { final int index = cursor.getColumnIndexOrThrow(column); return cursor.getString(index); } } finally { if (cursor != null) cursor.close(); } return null; }