android各种图片获取路径的方式

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();
    }
}

你可能感兴趣的:(android)