I'm trying to enable my widget in my app on the Android 4.2 lockscreen and it works fine, however it is unable to resolve any of the image uris. The error I get is this:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.tvshowfavs/cache/22kifo7sdmyet7x7kphdgch69: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at java.io.FileInputStream.<init>(FileInputStream.java:105)
at android.content.ContentResolver.openInputStream(ContentResolver.java:447)
at android.widget.ImageView.resolveUri(ImageView.java:636)
at android.widget.ImageView.setImageURI(ImageView.java:381)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:1146)
at android.widget.RemoteViews.performApply(RemoteViews.java:2304)
at android.widget.RemoteViews.apply(RemoteViews.java:2263)
at android.widget.RemoteViewsAdapter$RemoteViewsFrameLayout.onRemoteViewsLoaded(RemoteViewsAdapter.java:286)
at android.widget.RemoteViewsAdapter$RemoteViewsFrameLayoutRefSet.notifyOnRemoteViewsLoaded(RemoteViewsAdapter.java:335)
at android.widget.RemoteViewsAdapter$4.run(RemoteViewsAdapter.java:993)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
Anyone have any idea why it can't open an image that is stored on the emulated storage? This image was previously downloaded and cached using the Environment.getExternalStorageDirectory(), so it should be properly written to the storage directory. This is on a Nexus 10 that I'm receiving this exception when any of the images are attempted to be loaded. Any help is appreciated.
Alright, I figured out the problem. I was using the RemoteView method setImageUri(), which it looks as though won't work since the different process can't access the file. The solution is to use setImageViewBitmap() and to decode the bitmap yourself, like this, for example: BitmapFactory.decodeFile(Uri.parse(uri).getPath())
I find it strange that the setImageUri() works fine with launchers but not on the lockscreen, however.
Tomáš was right; using a content: Uri instead of a file: Uri fixed the problem for me.
See this sample project demonstrating how to serve Files via a ContentProvider from this SO answer.
Related
I am trying to copy the file from /storage/emulated/0/test.txt to /cache/SH_DIR/ via android user application ,
getting error like below
java.io.FileNotFoundException: /cache/test/test.txt: open failed: EACCES (Permission denied)
When I have created as system application like , Included Application code as past of AOSP then able to copy the file to /cache/SH_DIR/ location.
May I need to add anything in the SEpolicy to copy file to /cacahe/SH_DIR/ from user application.
Can you please help me , Thanks in advance
First of all, this is not a duplicate of Error: open failed: ENOENT (No such file or directory) I have been through this.
Second: Please read the whole question.
Third: The error was not in my code. I had to remove all filters from logcat and see this error.
This is strange, I was developing this app and using it until yesterday. Right now when I launched it on my device from Android Studio I see this error. When I remove the code that handles firebase auth and firebase UI this the error goes away.
Also, I don't know if it is related but, I had to uninstall and reinstall Android Studio and all SDKs this morning, I am facing this error after that.
I have looked at almost every resource out there, on StackOverflow and multiple gists on GitHub but none of them helped.
Any help will be appreciated.
Thank in advance.
12-26 12:17:50.061 1207-1315/? E/KernelUidCpuTimeReader: Failed to read uid_cputime
java.io.FileNotFoundException: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8862)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1685)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:232)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at java.io.FileReader.<init>(FileReader.java:66)
at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8862)
at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1685)
at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:232)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
I have required permission to read and write in manifest too
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Found the solution. For the newbies out there. The error occurred because of unstable network.
I dont know why the FileNotFound Error was thrown though. But I tested the same thing on five different devices and finally, only this makes sense. When I moved to a better internet connection the error seemed to resolve itself.
Hope this saves someone else's time.
My create method looks like this:
#Override
public void create () {
batch = new SpriteBatch();
FileHandle file = Gdx.files.external("file.txt");
file.writeString("My god, it's full of stars", false);
}
I also included:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
The Exception I get is this:
02-13 14:45:51.858 12439-12466/com.snowdevs.tweetiebirds E/AndroidRuntime: FATAL EXCEPTION: GLThread 1120
Process: com.snowdevs.tweetiebirds, PID: 12439
com.badlogic.gdx.utils.GdxRuntimeException: Error writing file: file.txt (External)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:353)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:339)
at com.snowdevs.tweetiebirds.TweetieBirdsGame.create(TweetieBirdsGame.java:22)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: Error writing file: file.txt (External)
at com.badlogic.gdx.files.FileHandle.writer(FileHandle.java:330)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:350)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:339)
at com.snowdevs.tweetiebirds.TweetieBirdsGame.create(TweetieBirdsGame.java:22)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/file.txt: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at com.badlogic.gdx.files.FileHandle.writer(FileHandle.java:322)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:350)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:339)
at com.snowdevs.tweetiebirds.TweetieBirdsGame.create(TweetieBirdsGame.java:22)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
at com.badlogic.gdx.files.FileHandle.writer(FileHandle.java:322)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:350)
at com.badlogic.gdx.files.FileHandle.writeString(FileHandle.java:339)
at com.snowdevs.tweetiebirds.TweetieBirdsGame.create(TweetieBirdsGame.java:22)
at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:254)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
I use a Nexus 5 with Android 6 Marshmallow for testing.
I searched and found that Android 6 uses Run Time Permissions, but the LibGDX developers say that it works even on Android 6. Is there a fix, either with or without Run Time Permissions?
I solved the problem by checking if the user has granted permission of external storage and request permision if not granted by using:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
this.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_REQUEST_CODE);
}
All of this is android-specific code and thus resides in the AndroidLauncher class.
I don't believe Nexus 5 has external storage (SD card).
Use this to test to find out -
boolean isExtAvailable = Gdx.files.isExternalStorageAvailable();
You can find more information here.
I had the same situation(Android 6, Nexus 4 No SD Card, libGDX 1.9.3):
I checked the external storage with
Gdx.files.isExternalStorageAvailable() // returns true
then get the fileHandle with
FileHandle file = Gdx.files.external("file.txt"); // no exception
then call
file.writeString("text",false); // throws GdxRuntimeException
So I checked on android side is the external storage really available with this code:
Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); // returns true
This also returned true. So it's not a libGDX issue, rather than an Android issue.
then I solved it with catching the exception and in that case writing the file to local storage.
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
Ok so i've installed everything that should be needed in order for APV and/or MuPDF to work, but it still crashes.
I'm not very good at using shells to install programs and all that, but i did follow the instructions included in the readme files as good as i was able to.
When i try to run the program now (APV) It works fine until i try to open a pdf file, where i get the errors:
FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
cx.hell.android.pdfview.OpenFileActivity.getPDF(OpenFileActivity.java:442)
cx.hell.android.pdfview.OpenFileActivity.startPDF(OpenFileActivity.java:403)
cx.hell.android.pdfview.OpenFileActivity.onCreate(OpenFileActivity.java:169)
android.app.Activity.performCreate(Activity.java:4465)
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
android.app.ActivityThread.access$600(ActivityThread.java:123)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
android.os.Handler.dispatchMessage(Handler.java:99)
android.app.ActivityThread.main(ActivityThread.java:4424)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load pdfview2: findLibrary returned null
java.lang.Runtime.loadLibrary(Runtime.java:365)
java.lang.System.loadLibrary(System.java:535) at cx.hell.android.pdfview.PDF.<clinit>(PDF.java:15)
I've installed everything in D:\Android , where i have the following subfolders:
apache-ant-1.8.3
android-ndk-r7c
android-sdk
Cygwin
apv (containing : pdfview\jni\ libraries like freetype, mupdf, jpeg, openjpg etc. also another version of android-ndk-r7c)
i've tried running all the build files included in the scrip documents like: build-native, scale-images, ndk-build![enter image description here][2]
This is a screen dump from build-native just before it finishes.
succesfull stuff happening
cp: cannot create regular file '../jni/freetype/include/freetype/config/ftoption.h': Permission denied
cp: cannot create regular file '../jni/freetype/include/freetype/config/sed008052': Permission denied
cp: cannot create regular file '../jni/freetype/include/freetype/config/sed007576': Permission denied
D:\Android\apv\pdfview\scripts\build-native.sh: line 31: gcc: command not found
D:\Android\apv\pdfview\scripts\build-native.sh: line 34: ../../scripts/fontdumpt: No such file or directory
I honestly have no idea how else to attack this and the tutorial at : http://mupdf.com/repos/mupdf/android/ReadMe.txt didn't do much for me. If anyone else have any experience using this then i'd really appreciate any help you could offer.
The application i'm making will be open source so by helping me you can get a good laugh at my code later on! :)
also, sorry for the shitty text but can't post images until i have 10 reputation
Thanks, Anders