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

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -