方法是先将图片的url获取到,然后再将url地址转换成图片的储存地址
public String getRealFilePath( final Context context, final Uri uri ) { //使用此方法就可以将url地址转换成图片的储存地址了
if ( null == uri ) return null;
final String scheme = uri.getScheme();
data2 = null;
if ( scheme == null )
data2 = uri.getPath();
else if ( ContentResolver.SCHEME_FILE.equals( scheme ) ) {
data2 = 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 ) {
data2 = cursor.getString( index );
}
}
cursor.close();
}
}
return data2;
}