0

I am trying to read a system file using bufferedReader in Android API=23 but it gives the following error: open failed: EACCES (Permission denied).

The file is read only. On the other hand, 'cat' command run in adb shell just works fine.

Also, File.exists() returns true for my file whereas File.canRead() returns false. Is it something related to the administrative/root access? Does adb shell give you root access to system?

P.S.:I have granted Read/Write permissions to the app (as per API 23)

3 Answers3

0

Android added new permission model for Android 6.0 (Marshmallow).

http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal

So you have to check Runtime Permission :

What Are Runtime Permissions?

With Android 6.0 Marshmallow, Google introduced a new permission model that allows users to better understand why an application may be requesting specific permissions. Rather than the user blindly accepting all permissions at install time, the user is now prompted to accept permissions as they become necessary during application use.

When to Implement the New Model?

it doesn’t require full support until you choose to target version 23 in your application. If you are targeting version 22 or below, your application will request all permissions at install time just as it would on any device running an OS below Marshmallow.

This information is taken from here :

Please check How to implement from this link :

http://www.captechconsulting.com/blogs/runtime-permissions-best-practices-and-how-to-gracefully-handle-permission-removal

Avinash Roy
  • 953
  • 1
  • 8
  • 25
0

If your file exists but can not read, please make sure the followings:
- Permission. Because you can read other files as you said, it may not a problem.
- It is not folder. check it by file.isDirectory().
- Check your file path. For example, it should not start like that: file:/... or /home/storage//th (when you mistakenly append with two dashes).

Quang Nguyen
  • 2,600
  • 2
  • 17
  • 24
0

I guess the problem was very much unique to my case. The file was a system file and my app was not given the Permission to read it. It was rectified after I signed my app as a system app.

Probable other solution might be if the app will have root permissions to read such file.

Thanks everyone for your suggestions and answers!!