Android实现兼容所有手机从本地SD上拿到到URL
来源:互联网 发布:江苏大学网络教学平台 编辑:程序博客网 时间:2024/04/30 19:26
我们有时从本地SD上去获取图片,写好了所有代码,高高兴兴的去运行,如在小米手机可以获取的图片的地址, 然后你在把你的程序放在华为手机上去运行,结果你发现跟你返回个Null,气得你要死,这到底是为什呢? 因为我们的手机制造厂家都定制了自己的一套系统。但是不用怕,我们有兼容所有手机的方法,这样妈妈就这也不用担心我们写不来代码了。
public static String getImageRealPathFromURI(Uri contentURI,Context context) { String result = ""; int idx = 0; Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { // Source is Dropbox or other similar local file path result = contentURI.getPath(); } else { cursor.moveToFirst(); String document_id = cursor.getString(0); MyLogUtils.d(Constants.LOG_TAG,"cursor:"+document_id); if (document_id.contains(":")) { String id = document_id.split(":")[1]; String[] column = { MediaStore.Images.Media.DATA }; String sel = MediaStore.Images.Media._ID + "=?"; Cursor cursorByColon =context. getContentResolver(). query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, column, sel, new String[]{ id }, null); int columnIndex = cursorByColon.getColumnIndex(column[0]); if (cursorByColon.moveToFirst()) { result = cursorByColon.getString(columnIndex); } cursorByColon.close(); } else { idx = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); result = cursor.getString(idx); } cursor.close(); } return result; }
0 0
- Android实现兼容所有手机从本地SD上拿到到URL
- android简单实现从网络下载文件到手机sd卡
- android 将应用程序从手机内存移动到SD卡
- Android手机从服务器更新软件到手机本地
- videoview实现视频引导页及从assets文件中读取文件到本地SD卡
- Android从远程服务器下载文件到本地sd卡中
- android保存图片到本地sd卡
- Android 保存View到本地SD卡
- 从URL读取文件保存到本地
- 从URL下载数据到本地变量
- android开发步步为营之15:默认让应用程序安装到手机外存sd卡上
- JAVA实现:将文件从本地上传到HDFS上、从HDFS上读取等操作
- Android中从windows系统push(推送)文件到虚拟机的sd卡上
- Java实现URL下载图片到本地
- 通过ContentProvider拿到手机所有短信
- 如何从Nokia手机把通讯录复制到Android手机上
- 从github上同步代码到本地
- 从本地上传项目到github上
- CSDN windows Live Writer
- 面向对象解析prototype(模型)
- 使用Xcode 7 beta免费真机调试iOS应用程序
- JVM内存管理总结
- PowerDesigner使用教程
- Android实现兼容所有手机从本地SD上拿到到URL
- HDU 3033------I love sneakers!
- EasyDarwin+ffmpeg进行PC(摄像头+麦克风)流媒体直播服务
- 《Redis Sentinel机制与用法(一)》
- 自己写的UnitY实用小工具或脚本——读取Texture序列帧动画
- 6. head 区的设置
- 关于QT下资源使用和资源占用内存过多的问题
- Failed to load platform plugin "windows"
- 第十三节 网络编程