我的资产文件夹中有一个zip文件,我想要一个内容uri。
我可以使用以下方法获取文件uri:
final Uri uri = Uri.fromFile(new File("file:///android_asset/xyz.zip"));
对于内容uri,我尝试使用:
final Uri uri = Uri.parse("content://com.example.myproject/xyz.zip");
但是它不起作用吗?
答案 0 :(得分:0)
尝试此代码
InputStream inputStream = am.open("myfoldername/myfilename");
File file = createFileFromInputStream(inputStream);
final Uri uri = Uri.fromFile(file);
private File createFileFromInputStream(InputStream inputStream) {
try{
File f = new File(my_file_name);
OutputStream outputStream = new FileOutputStream(f);
byte buffer[] = new byte[1024];
int length = 0;
while((length=inputStream.read(buffer)) > 0) {
outputStream.write(buffer,0,length);
}
outputStream.close();
inputStream.close();
return f;
}catch (IOException e) {
//Logging exception
}
return null;
}