Android获取图片Uri/path
来源:互联网 发布:java 蓝牙通信协议 编辑:程序博客网 时间:2024/05/22 23:16
ANDROID 4.4以上:
display函数
@TargetApi(19)private void handleImageOnKitKat(Intent data){ String imagePath = null; Uri uri = data.getData(); if(DocumentsContract.isDocumentUri(this,uri)){ String docID = DocumentsContract.getDocumentId(uri); if("com.android.providers.media.documents".equals(uri.getAuthority())) { String id = docID.split(":")[1]; String selection = MediaStore.Images.Media._ID + "=" +id; imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection); } else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){ Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),Long.valueOf(docID)); imagePath = getImagePath(contentUri,null); } } else if("content".equalsIgnoreCase(uri.getScheme())) { imagePath = getImagePath(uri,null); } else if ("file".equalsIgnoreCase(uri.getScheme())){ imagePath = uri.getPath(); } displayImage(imagePath); }
4.4以下
private void handleImageBeforeKitKat(Intent data){ Uri uri = data.getData(); String imagePath = getImagePath(uri,null); displayImage(imagePath); }
private String getImagePath(Uri uri, String selection){ String path = null; Cursor cursor = getContentResolver().query(uri,null,selection,null,null); if(cursor != null){ path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); } cursor.close(); return path;}
display函数
private void displayImage(String imagePath){ if(imagePath != null){ BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeFile(imagePath,options); showview.setImageBitmap(bitmap); } else{ Toast.makeText(this,"failed to get image",Toast.LENGTH_SHORT).show(); } }}
阅读全文
0 0
- Android获取图片Uri/path
- android 7.0 图片path转Uri
- Android根据图片Uri获取图片绝对路径
- Android根据图片Uri获取图片绝对路径
- Android根据URI获取图片绝对路径
- android 图片路径path和uri之间的相互转换
- Android Uri to Path
- Android URI path 转化
- 绝对路径获取图片URI
- uri获取图片路径
- 【Android-图片小技巧】通过给定的uri获取图片
- android 通过图片的uri来获取图片的绝对路径
- Android手机读取相册图片,根据URI获取图片路径
- Android 获取图库图片 根据uri获取路径
- Android之根据图片的Uri获取对应的路径
- android 通过uri获取bitmap图片并压缩
- android 通过uri获取bitmap图片并压缩
- android 小米手机不能正确获取图片uri的问题
- Python map()函数
- KMP算法
- HDU 6060-RXD and dividing(多校训练第三场->DFS)
- 《Android开发艺术探索》读书笔记-第四章 View的工作原理
- QS Network (最小生成树——prim方法)
- Android获取图片Uri/path
- java 环境变量的配置
- 1019. General Palindromic Number (20)
- 2017.8.1暑假集训第二天(下午训练赛)
- Tensorflow学习笔记(2)-基本运算
- 七月小结
- 洛谷1983(DAG上最长路)
- 中国剩余定理介绍
- 自动驾驶的技术架构和生态发展