android - ContentResolver openInputStream() throws FileNotFound on existing file -
i have apparently simple code
file path = environment.getexternalstoragepublicdirectory(environment.directory_pictures); file testfile = new file(path,"image.jpg"); log.d(tag,"testfile: " + testfile + " exists: " + testfile.exists()); uri uri = uri.fromfile(testfile); contentresolver cr = context.getcontentresolver(); inputstream istr = cr.openinputstream(uri);
the output is:
testfile: /storage/emulated/0/pictures/image.jpg exists: true
the uri value file:///storage/emulated/0/pictures/image.jpg
. looks same file, openinputstream() throws filenotfoundexception.
any idea why? on android 6.0.1.
add permission androidmanifest.xml
<uses-permission android:name="android.permission.read_external_storage" />
when targetsdkversion 23 or above (android 6), putting in androidmanifest.xml not enough , have request permission @ runtime.
Comments
Post a Comment