我的 asset 文件夹中有一个 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");但它不起作用?
1 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
试试这个代码
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;
}
添加回答
举报
0/150
提交
取消