Issue
The file uri is known, such as
`file:///mnt/sdcard/Download/AppSearch_2213333_60.apk`
I want to check if this file can open or not in background, how to do?
Solution
Check if a file of a path exists like this:
File file = new File("/mnt/sdcard/Download/AppSearch_2213333_60.apk" );
if (file.exists()) {
//Do something
}
Keep in mind to remove something like "file://" etc. otherwise use:
File file = new File(URI.create("file:///mnt/sdcard/Download/AppSearch_2213333_60.apk").getPath());
if (file.exists()) {
//Do something
}
Also you have to set proper permissions for your app in the AndroidManifest.xml to access the sdcard:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Answered By - alex
Answer Checked By - Pedro (JavaFixing Volunteer)