FileInputStream can't read file in Android R - android

File file = new File(filePath);
InputStreamReader is = new InputStreamReader(new FileInputStream(file), charsetName);
simple piece of code.
i checked the following:
file!=null
file.isFile()
file.exists()
file.canRead()
everything is true. The program have the permission and can actually read this existing file, but put it in a FileInputStream, it throws the following exception:
java.io.FileNotFoundException: /storage/emulated/0/XNR/Setting.gson: open failed: EFAULT (Bad address)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:159)
...
Caused by: android.system.ErrnoException: open failed: EFAULT (Bad address)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7372)
at libcore.io.IoBridge.open(IoBridge.java:478)
at java.io.FileInputStream.<init>(FileInputStream.java:159) 
... 
it works well only on a api 23 emulator now. maybe the issue is cause by some new mechanics of newer version android api?
funny thing is, i developed and tested it on a android r emulator exclusively 2 months ago and everything is fine, after tested on several actuall devices, the project was deemed done and finished, it sat in my hard drive untouched for 2 months, i can even see the same .gson file generated by it. almost looks like it just went bad on it's own.

Using getFilesDir() or getExternalFilesDir(String) to access storage instead of using Environment.getExternalStorageDirectory() solved the problem, android no longer supports that since q based on the comment above.

Related

Webview error variations_seed (No such file or directory)

I tried to install my app in different versions of Android above 23 and it works perfectly.
I have the min sdk is 21 (Android 5.0) so I tried to test it in android 6.0 & 5.0 and I have the following error :
E/cr_VariationsUtils: Failed reading seed file
"/data/user/0/app_package/app_webview/variations_seed":
/data/user/0/app_package/app_webview/variations_seed (No such file
or directory)
Any idea ?
Probably not the same issue(?),but may help someone else.
I had a similar issue on my Android app, error was coming from the ION library and the error msg was:
Failed reading seed file "/data/user/0/{package name}/app_webview/variations_seed_new": /data/user/0/{package name}/app_webview/variations_seed_new (No such file or directory)
2021-12-10 15:30:56.177 15083-15225/{package name} E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY)
And the solution (for me) was to update the ION version I was using.
I had: implementation 'com.koushikdutta.ion:ion:3.0.4'
and the fix was to change it to:
implementation 'com.koushikdutta.ion:ion:3.1.0'
because android latest version androidx does not consist such file so search for that file that file in androidx library
Are you noticing any crashes in your app or any ANRs?
You don't need to worry about these logs errors, they are internal errors in WebView and they should not affect your app.

How to load an SSL certificate using an input stream for Retrofit

I need to add my SSL certificate for Retrofit in Android but I can't find the file using Google's example code for doing this.
Here's the example from Google that I'm using https://developer.android.com/training/articles/security-ssl
When running:
val caInput: InputStream = BufferedInputStream(FileInputStream("rest_of_the_world_production.crt"))
I get the error
Caused by: java.io.FileNotFoundException: rest_of_the_world_production.crt: open failed: ENOENT (No such file or directory)
and an instant crash when trying to access the file. The file is currently stored as a crt file under res/raw/rest_of_the_world_production.crt so why can't Android find it?
Do it as follows:
InputStream cert = context.getResources().openRawResource(R.raw.my_cert);
// Place your 'my_cert.crt' file in `res/raw`
So turns out I had imported
android.R
instead of
com.myApp.R
Changing this allowed me to find my certificate and import it.

Google Play pre-launch report only, java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed

I'm seeing this error in the pre-launch report:
Caused by: b.b.a.h.h: Error loading audio file: sounds/mysound.ogg
...
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:332)
The App is working fine on a real device, and also in the emulator. It only seems to show up in the pre-launch report (all devices fail).
Has anyone come across this before?
The following StackOverflow post looks related:
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
However I ran the command unzip -lv MyApplication.apk and it says the sound files are not compressed ("Stored" with 0%).
I also tried explicitly adding
android {
aaptOptions {
noCompress "ogg"
}
}
but to no avail.
Is this a problem with the Firebase emulators? One of the devices listed as failing matches a real device configuration that I have tested as working on a physical device.
Also, I'm using the LibGDX framework. I load the assets in the loading screen like so:
assetManager.load("sounds/mysound.ogg", Sound.class);
And then I get them using:
assetManager.get("sounds/mysound.ogg", Sound.class);

Android Exception : java.io.IOException: open failed: EACCES (Permission denied) [duplicate]

This question already has answers here:
Exception 'open failed: EACCES (Permission denied)' on Android
(34 answers)
Closed 8 years ago.
For some strange reason, am constantly facing an issue with different types of Android devices, for saving the captured images on the device storage.
Here, is the detailed error log, of what, actually am getting.
java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:940)
at com.parkhya.pick_for_shareAflash.HomeActivity.resizeImage(HomeActivity.java:456)
at com.parkhya.pick_for_shareAflash.HomeActivity.onActivityResult(HomeActivity.java:393)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:933)
Although, all the other Android apps, like, Instagram and others, are able to save the camera clicked images on the devices.
Anybody, can you please suggest, what should I do, in order for my app, to save the camera pictures in sdcard.
This may help you. I face the same issue when writing the file on sdcard. I have set all required permission to write the file but I used the file object like below:
Wrong:
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile()+fileName);
Correct:
File myFile = new File(Environment.getExternalStorageDirectory().getAbsoluteFile(), fileName);
That means the path was wrong.
Solution what i find is
edit the Emulator
1. go to android virtual device manager and then edit the emulator
2. set say 100 MB for Sd card for the respected emulator and say Ok
3. save and close emulator and start
4. path saved is click DDMS mnt/sdcard/yourfilename
it worked for me the app is not giving Error and is working

FileNotFoundException on Nexus 4

in my app I need to save some files in the device, to save the file I use:
Environment.getExternalStorageDirectory().getAbsolutePath() + "mypath"
to get the path. This work on almost all the devices but I have some problems in other devices (nexus4 for example..)
the error is:
java.lang.RuntimeException: java.io.FileNotFoundException:
/mnt/sdcard/musicfall/data/cache/.first_activation: open failed: ENOENT
(No such file or directory)
The strange thing is that it works on many device, and for this reason I can't see the problem.
PS: in "mypath" I use mkdir to create the folders that I need

Categories

Resources