Java Code Examples for android.app.Activity#managedQuery()
The following examples show how to use
android.app.Activity#managedQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageUtils.java From wakao-app with MIT License | 6 votes |
/** * 获取SD卡中最新图片路径 * * @return */ public static String getLatestImage(Activity context) { String latestImage = null; String[] items = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor .moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }
Example 2
Source File: ImageUtils.java From wakao-app with MIT License | 6 votes |
/** * 通过uri获取文件的绝对路径 * * @param uri * @return */ public static String getAbsoluteImagePath(Activity context, Uri uri) { String imagePath = ""; String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery(uri, proj, // Which columns to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (cursor != null) { int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { imagePath = cursor.getString(column_index); } } return imagePath; }
Example 3
Source File: PhotoUtils.java From zone-sdk with MIT License | 6 votes |
/** * 通过uri获取文件的绝对路径 * * @param uri * @return */ public static String getAbsoluteImagePath(Activity context, Uri uri) { String imagePath = ""; String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery(uri, proj, // Which columns to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (cursor != null) { int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { imagePath = cursor.getString(column_index); } } return imagePath; }
Example 4
Source File: PhotoUtils.java From zone-sdk with MIT License | 6 votes |
/** * 获取SD卡中最新图片路径 * * @return */ public static String getLatestImage(Activity context) { String latestImage = null; String[] items = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA }; Cursor cursor = context.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor .moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }
Example 5
Source File: FileUtils.java From VideoMeeting with Apache License 2.0 | 6 votes |
/** * 把媒体文件uri转为File对象 */ public static File uri2File(Activity aty, Uri uri) { if (android.os.Build.VERSION.SDK_INT < 11) { // 在API11以下可以使用:managedQuery String[] proj = { MediaStore.Images.Media.DATA }; @SuppressWarnings("deprecation") Cursor actualimagecursor = aty.managedQuery(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor .getString(actual_image_column_index); return new File(img_path); } else { // 在API11以上:要转为使用CursorLoader,并使用loadInBackground来返回 String[] projection = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(aty, uri, projection, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return new File(cursor.getString(column_index)); } }
Example 6
Source File: FileUtil.java From AndroidStudyDemo with GNU General Public License v2.0 | 6 votes |
/** * 把uri转为File对象 * * @param activity Activity * @param uri 文件Uri * @return File对象 */ public static File uri2File(Activity activity, Uri uri) { if (Build.VERSION.SDK_INT < 11) { // 在API11以下可以使用:managedQuery String[] proj = {MediaStore.Images.Media.DATA}; @SuppressWarnings("deprecation") Cursor actualimagecursor = activity.managedQuery(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor .getString(actual_image_column_index); return new File(img_path); } else { // 在API11以上:要转为使用CursorLoader,并使用loadInBackground来返回 String[] projection = {MediaStore.Images.Media.DATA}; CursorLoader loader = new CursorLoader(activity, uri, projection, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return new File(cursor.getString(column_index)); } }
Example 7
Source File: ImageUtils.java From wakao-app with MIT License | 6 votes |
/** * 获取图片缩略图 只有Android2.1以上版本支持 * * @param imgName * @param kind * MediaStore.Images.Thumbnails.MICRO_KIND * @return */ public static Bitmap loadImgThumbnail(Activity context, String imgName, int kind) { Bitmap bitmap = null; String[] proj = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME }; Cursor cursor = context.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, MediaStore.Images.Media.DISPLAY_NAME + "='" + imgName + "'", null, null); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { ContentResolver crThumb = context.getContentResolver(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1; bitmap = MethodsCompat.getThumbnail(crThumb, cursor.getInt(0), kind, options); } return bitmap; }
Example 8
Source File: ImageUtils.java From monolog-android with MIT License | 6 votes |
/** * 获取SD卡中�?新图片路�? * * @return */ public static String getLatestImage(Activity context) { String latestImage = null; String[] items = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA}; Cursor cursor = context.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null, null, MediaStore.Images.Media._ID + " desc"); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor .moveToNext()) { latestImage = cursor.getString(1); break; } } return latestImage; }
Example 9
Source File: ImageUtils.java From monolog-android with MIT License | 6 votes |
/** * 获取图片缩略�? 只有Android2.1以上版本支持 * * @param imgName * @param kind MediaStore.Images.Thumbnails.MICRO_KIND * @return */ @SuppressWarnings("deprecation") public static Bitmap loadImgThumbnail(Activity context, String imgName, int kind) { Bitmap bitmap = null; String[] proj = {MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME}; Cursor cursor = context.managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, MediaStore.Images.Media.DISPLAY_NAME + "='" + imgName + "'", null, null); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { ContentResolver crThumb = context.getContentResolver(); Options options = new Options(); options.inSampleSize = 1; bitmap = getThumbnail(crThumb, cursor.getInt(0), kind, options); } return bitmap; }
Example 10
Source File: ImageUtils.java From monolog-android with MIT License | 6 votes |
/** * 通过uri获取文件的绝对路�? * * @param uri * @return */ @SuppressWarnings("deprecation") public static String getAbsoluteImagePath(Activity context, Uri uri) { String imagePath = ""; String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = context.managedQuery(uri, proj, // Which columns to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (cursor != null) { int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); if (cursor.getCount() > 0 && cursor.moveToFirst()) { imagePath = cursor.getString(column_index); } } return imagePath; }
Example 11
Source File: FileUtils.java From KJFrameForAndroid with Apache License 2.0 | 6 votes |
/** * 把uri转为File对象 */ public static File uri2File(Activity aty, Uri uri) { if (SystemTool.getSDKVersion() < 11) { // 在API11以下可以使用:managedQuery String[] proj = { MediaStore.Images.Media.DATA }; @SuppressWarnings("deprecation") Cursor actualimagecursor = aty.managedQuery(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor .getString(actual_image_column_index); return new File(img_path); } else { // 在API11以上:要转为使用CursorLoader,并使用loadInBackground来返回 String[] projection = { MediaStore.Images.Media.DATA }; CursorLoader loader = new CursorLoader(aty, uri, projection, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return new File(cursor.getString(column_index)); } }
Example 12
Source File: FileUtils.java From Common with Apache License 2.0 | 5 votes |
/** * 把uri转为File对象 */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static File uri2File(Activity aty, Uri uri) { if (SystemTool.getSDKVersion() < 11) { // 在API11以下可以使用:managedQuery String[] proj = {MediaStore.Images.Media.DATA}; @SuppressWarnings("deprecation") Cursor actualimagecursor = aty.managedQuery(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor .getString(actual_image_column_index); return new File(img_path); } else { // 在API11以上:要转为使用CursorLoader,并使用loadInBackground来返回 String[] projection = {MediaStore.Images.Media.DATA}; CursorLoader loader = new CursorLoader(aty, uri, projection, null, null, null); Cursor cursor = loader.loadInBackground(); int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return new File(cursor.getString(column_index)); } }
Example 13
Source File: SystemUtils.java From letv with Apache License 2.0 | 5 votes |
public static String getRealPathFromUri(Activity activity, Uri uri) { Cursor managedQuery = activity.managedQuery(uri, new String[]{"_data"}, null, null, null); if (managedQuery == null) { return null; } int columnIndexOrThrow = managedQuery.getColumnIndexOrThrow("_data"); managedQuery.moveToFirst(); return managedQuery.getString(columnIndexOrThrow); }
Example 14
Source File: GetPathFromUri4kitkat.java From nono-android with GNU General Public License v3.0 | 5 votes |
/** * 专为Android4.4设计的从Uri获取文件绝对路径,以前的方法已不好使 */ public static String getPath(Activity context,final Uri uri){ if (Build.VERSION.SDK_INT < 19) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor actualimagecursor = context.managedQuery(uri, proj, null, null, null); int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); return actualimagecursor.getString(actual_image_column_index); } else { return getPathKitkat(context, uri); } }
Example 15
Source File: ActivityUtils.java From Kratos with GNU Lesser General Public License v3.0 | 5 votes |
public static String getRealPathFromURI(Uri contentUri, Activity activity) { String[] proj = {MediaStore.Images.Media.DATA}; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
Example 16
Source File: Utility.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static String getPicPathFromUri(Uri uri, Activity activity) { String value = uri.getPath(); if (value.startsWith("/external")) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else { return value; } }
Example 17
Source File: Utility.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static String getPicPathFromUri(Uri uri, Activity activity) { String value = uri.getPath(); if (value.startsWith("/external")) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else { return value; } }
Example 18
Source File: Utils.java From whiteboard with Apache License 2.0 | 5 votes |
/** * ��ȡURI�а������ļ�·�� * * @param contentUri * @param activity * @return */ public String getRealPathFromURI(Uri contentUri, Activity activity) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index).replace(" ", "%20"); }
Example 19
Source File: MediaUtils.java From android-open-project-demo with Apache License 2.0 | 5 votes |
public static String getPath(Activity activity, Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, projection, null, null, null); activity.startManagingCursor(cursor); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
Example 20
Source File: Utility.java From iBeebo with GNU General Public License v3.0 | 5 votes |
public static String getPicPathFromUri(Uri uri, Activity activity) { String value = uri.getPath(); if (value.startsWith("/external")) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = activity.managedQuery(uri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else { return value; } }