List of usage examples for android.content CursorLoader CursorLoader
public CursorLoader(Context context, Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder)
From source file:Main.java
@SuppressLint("NewApi") public static String getRealPathFromURI_API11to18(Context context, Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; String result = null;/*w w w. j a va 2 s .c o m*/ CursorLoader cursorLoader = new CursorLoader(context, contentUri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); result = cursor.getString(column_index); } return result; }
From source file:Main.java
@SuppressLint("NewApi") public static String getRealPathFromUriApi11to18(Context context, Uri contentUri) { String[] projection = { MediaStore.Images.Media.DATA }; String result = null;/*from ww w . j a v a 2s.c o m*/ CursorLoader cursorLoader = new CursorLoader(context, contentUri, projection, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); result = cursor.getString(columnIndex); } return result; }
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. ja v a 2 s . co m*/ public static String getRealPathFromURI(Activity activity, Uri contentUri) { String releaseNumber = Build.VERSION.RELEASE; if (releaseNumber != null) { /* ICS Version */ if (releaseNumber.length() > 0 && releaseNumber.charAt(0) == '4') { 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(); } return strFileName; } /* GB Version */ else if (releaseNumber.startsWith("2.3")) { 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(); } 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 *//*from w w w .j a v a 2 s .com*/ 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 *///from ww w. j a va 2 s . c om @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
/** * Using code from this link: http://hmkcode.com/android-display-selected-image-and-its-real-path/ * This method will return the absolute path Android.net.Uri. * NOTE!!! THIS DOES NOT SUPPORT API 10 OR BELOW!!! IF YOU NEED TO WORK WITH THAT, CHECK LINK ABOVE * @param context Context// w ww. jav a 2s . co m * @param uri Uri to check * @return String for the absolute path */ public static String getAbsolutePath(Context context, android.net.Uri uri) { if (Build.VERSION.SDK_INT >= 19) { try { String filePath = ""; String wholeID = DocumentsContract.getDocumentId(uri); // Split at colon, use second item in the array String id = wholeID.split(":")[1]; String[] column = { MediaStore.Images.Media.DATA }; // where id is equal to String sel = MediaStore.Images.Media._ID + "=?"; Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[] { id }, null); int columnIndex = cursor.getColumnIndex(column[0]); if (cursor.moveToFirst()) { filePath = cursor.getString(columnIndex); } cursor.close(); return filePath; } catch (Exception e) { e.printStackTrace(); return null; } } else { try { String[] proj = { MediaStore.Images.Media.DATA }; String result = null; CursorLoader cursorLoader = new CursorLoader(context, uri, proj, null, null, null); Cursor cursor = cursorLoader.loadInBackground(); if (cursor != null) { int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); result = cursor.getString(column_index); } return result; } catch (Exception e) { e.printStackTrace(); return null; } } }
From source file:com.caju.uheer.app.services.infrastructure.ContactablesLoaderCallbacks.java
@Override public Loader<Cursor> onCreateLoader(int loaderIndex, Bundle args) { String query = ""; JSONArray nearbyUsers = new JSONArray(); Uri uri = Uri.withAppendedPath(CommonDataKinds.Contactables.CONTENT_FILTER_URI, query); // Sort results such that rows for the same contact stay together. String sortBy = CommonDataKinds.Contactables.LOOKUP_KEY; CursorLoader cursorLoader = new CursorLoader(mContext, // Context uri, // URI representing the table/resource to be queried null, // projection - the list of columns to return. Null means "all" null, // selection - Which rows to return (condition rows must match) null, // selection args - can be provided separately and subbed into selection. sortBy); // string specifying sort order try {//from w ww . j av a 2 s .c o m // Parsing the JSON received from server. String nearbyUsersString = args.getString("jsonString"); nearbyUsers = new JSONObject(nearbyUsersString).getJSONArray("nearbyUsers"); } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < nearbyUsers.length(); i++) { // Log.d("json", "" + nearbyUsers.getJSONObject(0).get("email")); try { query = nearbyUsers.getJSONObject(i).getString("email"); } catch (JSONException e) { e.printStackTrace(); } // query = args.getString("query"); uri = Uri.withAppendedPath(CommonDataKinds.Contactables.CONTENT_FILTER_URI, query); cursorLoader = new CursorLoader(mContext, // Context uri, // URI representing the table/resource to be queried null, // projection - the list of columns to return. Null means "all" null, // selection - Which rows to return (condition rows must match) null, // selection args - can be provided separately and subbed into selection. sortBy); // string specifying sort order Cursor cursor = cursorLoader.loadInBackground(); Toast.makeText(mContext, "entrei no cursorLoader", Toast.LENGTH_LONG).show(); if (cursor.getCount() == 0) { return cursorLoader; } int nameColumnIndex = cursor.getColumnIndex(CommonDataKinds.Contactables.DISPLAY_NAME); int lookupColumnIndex = cursor.getColumnIndex(CommonDataKinds.Contactables.LOOKUP_KEY); cursor.moveToFirst(); String lookupKey = ""; String displayName = ""; do { String currentLookupKey = cursor.getString(lookupColumnIndex); if (!lookupKey.equals(currentLookupKey)) { displayName = cursor.getString(nameColumnIndex); lookupKey = currentLookupKey; } } while (cursor.moveToNext()); Toast.makeText(mContext, displayName, Toast.LENGTH_LONG).show(); try { JSONObject jobj = new JSONObject().put("name", displayName); if (!nearbyUsers.getJSONObject(i).has("channel")) { double[] geoPoint = new double[2]; geoPoint[0] = nearbyUsers.getJSONObject(i).getJSONObject("geoPoint").getDouble("latitude"); geoPoint[1] = nearbyUsers.getJSONObject(i).getJSONObject("geoPoint").getDouble("longitude"); jobj.put("lat", geoPoint[0]); jobj.put("lon", geoPoint[1]); } else { String channel = nearbyUsers.getJSONObject(i).getString("channel"); jobj.put("channel", channel); } usersFound.put(jobj); } catch (JSONException e) { e.printStackTrace(); } } return cursorLoader; }
From source file:com.google.samples.apps.iosched.ui.HashtagsFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { if (id == HashtagsQuery.TOKEN) { return new CursorLoader(getActivity(), ScheduleContract.Hashtags.CONTENT_URI, HashtagsQuery.PROJECTION, null, null, ScheduleContract.Hashtags.HASHTAG_ORDER); }/* w w w . ja va2 s . c om*/ return null; }
From source file:com.hybris.mobile.lib.commerce.loader.ContentAdapterLoader.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // Before doing the request if (mOnRequestListener != null) { mOnRequestListener.beforeRequest(); }/*from w w w .j a va 2 s . co m*/ // Order by and Limit String orderBy = CatalogContract.DataBaseDataSimple._ID; if (StringUtils.isNotBlank(mOrderBy)) { orderBy = mOrderBy; } if (mLimitFrom != -1 && mLimitTo != -1) { orderBy += " LIMIT " + mLimitFrom + ", " + mLimitTo; } return new CursorLoader(mContext, getUri(), null, null, null, orderBy); }
From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListResultMetaAttributesActivity.java
@Override protected Loader<Cursor> onCreateLoader(int id, Bundle args, ListHierarchyType type) { Uri uri = Uri.parse(/*from w ww . jav a 2 s. c om*/ DBContentProvider.RESULT_METADATA_URI + "/" + id + "/" + DBContentProvider.RESULT_META_ATTRIBUTES); CursorLoader cursorLoader = new CursorLoader(this, uri, null, null, null, null); return cursorLoader; }