Android FileNotFound canread and exists false media whatsapp files


Android FileNotFound canread and exists false media whatsapp files



I'm trying to read a file that exists, but I can not. Thanks!



enter image description here


File f = new File("/mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20180628-WA0000.jpg");

File sdDir = Environment.getExternalStorageDirectory();
Log.w("Whatsapp","#SDDIR CANREAD? "+ sdDir.canRead() +" PATH: "+ sdDir.getAbsolutePath());

f.setReadable(true,false);
Log.w("Whatsapp","#FILE: "+ f.getName() +" l:"+ f.length() +" exists:"+ f.exists() +" canRead:"+ f.canRead() +" PATH: "+ f.getPath() +" ABSOLUTE: "+ f.getAbsolutePath());



LOG


#SDDIR CANREAD? false PATH: /storage/emulated/0
#FILE: IMG-20180628-WA0000.jpg l:0 exists:false canRead:false PATH: /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20180628-WA0000.jpg ABSOLUTE: /mnt/sdcard/WhatsApp/Media/WhatsApp Images/IMG-20180628-WA0000.jpg



enter image description here



enter image description here



AndroidManifest Permissions


<uses-permission android:name="ANDROID.PERMISSION.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="ANDROID.PERMISSION.MANAGE_DOCUMENTS" />




2 Answers
2



First, you do not have arbitrary read-write access to removable storage.



Second, most things in Android are case-sensitive. So, your <uses-permission> elements will not work.


<uses-permission>



Third, you cannot hold the MANAGE_DOCUMENTS permission, as that is not available for ordinary apps.


MANAGE_DOCUMENTS



So you can fix your manifest by replacing your existing <uses-permission> elements with:


<uses-permission>


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>



However, you still may not have access to that particular file.





WORKS! Thank u so much!!
– Marco Costa
Jun 30 at 18:40



Works!


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>



enter image description here






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API