打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
android图片文件的路径地址与Uri的相互转换
/**
 * Try to return the absolute file path from the given Uri
 *
 * @param context
 * @param uri
 * @return the file path or null
 */
public static String getRealFilePath( final Context context, final Uri uri ) {
    if ( null == uri ) return null;
    final String scheme = uri.getScheme();
    String data = null;
    if ( scheme == null )
        data = uri.getPath();
    else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
        data = uri.getPath();
    } else if ( ContentResolver.SCHEME_CONTENT.equals( scheme ) ) {
        Cursor cursor = context.getContentResolver().query( uri, new String[] { ImageColumns.DATA }, null, null, null );
        if ( null != cursor ) {
            if ( cursor.moveToFirst() ) {
                int index = cursor.getColumnIndex( ImageColumns.DATA );
                if ( index > -1 ) {
                    data = cursor.getString( index );
                }
            }
            cursor.close();
        }
    }
    return data;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android 文件选择的实现代码
android 通话记录的增删改查 .
Content Provider(二)之 FileProvider 实现应用文件共享
android 通过手机号查找联系人的头像
Android学习笔记——文件路径(/mnt/sdcard/...)、Uri(conten...
Android多媒体分析(二)MediaStore
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服