android各种图片获取路径的方式
16lz
2021-01-23
1、通过R.drawable.**来获取文件的路径 protected static String getAbsoluteImagePath(Context context, Uri uri) {
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query( 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)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index); }
Resources r = app.getApp().getApplicationContext().getResources(); Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + r.getResourcePackageName(R.drawable.favorite_detail_line) + "/" + r.getResourceTypeName(R.drawable.favorite_detail_line) + "/" + r.getResourceEntryName(R.drawable.favorite_detail_line)); String headLineString = getAbsoluteImagePath(app.getApp().getApplicationContext(), uri); 2、获取到表情路径的方法 Drawable d = EmoWindow.getDrawable(app.getApp(), app.getApp().getResources().getDisplayMetrics().density, i); if(d != null){ String filepath = ""; try { URLDrawable ud = (URLDrawable)d; if (ud.hasDiskCache()) { filepath = ud.getDiskCache().getAbsolutePath(); } } catch (Exception e) { e.printStackTrace(); } }
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = context.getContentResolver().query( 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)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index); }
Resources r = app.getApp().getApplicationContext().getResources(); Uri uri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + r.getResourcePackageName(R.drawable.favorite_detail_line) + "/" + r.getResourceTypeName(R.drawable.favorite_detail_line) + "/" + r.getResourceEntryName(R.drawable.favorite_detail_line)); String headLineString = getAbsoluteImagePath(app.getApp().getApplicationContext(), uri); 2、获取到表情路径的方法 Drawable d = EmoWindow.getDrawable(app.getApp(), app.getApp().getResources().getDisplayMetrics().density, i); if(d != null){ String filepath = ""; try { URLDrawable ud = (URLDrawable)d; if (ud.hasDiskCache()) { filepath = ud.getDiskCache().getAbsolutePath(); } } catch (Exception e) { e.printStackTrace(); } }
更多相关文章
- Android将bitmap保存到自定义路径
- android 根据SD卡中图片路径读取并显示SD中的图片――源代码
- android读取SDCard任意路径下的文件
- Android之adt 23找不到NDK路径设置解决方案
- Android 模拟器中AVD路径的修改
- Android各版本 内外卡真实路径
- AVD(android virtual device)路径设置
- APK安装路径移动至外部存储设备
- android实现图片按任意路径截取