android各种图片获取路径的方式
16lz
2022-06-16
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获取版本号
- Android(安卓)调用相册或相机选择图片
- Android:获取网页源代码
- android获取google邮箱
- Android获取、设置Wifi状态
- Android(安卓)获取drawable中图片的高度宽度
- 【Android】【基础】获取屏幕宽高
- Android(安卓)模拟器中AVD路径的修改
- Pycharm安装PyQt5的详细教程