Vij*_*bey 12
您必须创建一个新URL
对象,然后在该URL
实例上打开流.一个例子如下.
try {
URL url = uri.toURL(); //get URL from your uri object
InputStream stream = url.openStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
您应该使用ContentResolver来获取InputStream:
InputStream is = getContentResolver().openInputStream(uri);
Run Code Online (Sandbox Code Playgroud)
代码在 Activity 对象范围内有效。