How to get Uri of res folder?

前端 未结 1 363
旧巷少年郎
旧巷少年郎 2020-12-29 00:32

I am trying to get the Uri of an image I have in the drawable folder. I tried many possible ways but nothing seems to work. Can anyone suggest me how to get the Uri of res f

1条回答
  •  孤城傲影
    2020-12-29 01:22

    Well, it's actually quite easy. a base URI for a resource in your package would be something like the following possibilities:

    android.resource://[package]/[resource_id]
    android.resource://[package]/[res type]/[res name]
    

    So the following would be managable.

    String pkgName = getApplicationContext().getPackageName();
    Uri path = Uri.parse("android.resource://"+pkgName+"/" + R.drawable.icon);
    Uri otherPath = Uri.parse("android.resource://"+pkgName+"/drawable/icon");
    

    You can find more about this at http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html

    0 讨论(0)
提交回复
热议问题