我的 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
提交
取消