简体   繁体   English

在Android中获取uri.parse()的文件路径

[英]get file path for uri.parse() in android

I have the location of a file, 我有文件的位置,

D:\\Android\\WorkSpace\\myApp\\res\\drawable-hdpi\\image.PNG D:\\ Android \\ WorkSpace \\ myApp \\ res \\ drawable-hdpi \\ image.PNG

how can I get the file path to use inside uri.parse()? 如何获取在uri.parse()中使用的文件路径?

I found it much easier to use "getPackageName()" method. 我发现使用“ getPackageName()”方法要容易得多。 so here is what worked for me, 所以这对我有用

 Uri path = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image));

pass the path to your URI path like as follows.may be in two ways: 如下所示将路径传递到您的URI路径。可能有两种方式:

1.Uri path=Uri.parse("android.resource://" + PACKAGE_NAME + "/" + R.drawable.image);
2. Uri path=uri.parse("android.resource://"+PACKAGE_NAME+"/"+"drawable/image"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM