Android Question open failed: EACCES (Permission denied)

Status
Not open for further replies.

FERNANDO SILVEIRA

Active Member
Licensed User
Hello guys,

I'm trying Erel's test app (1.zip file from this thread, page 2) and having Permission Denied when choosing a photo from photo Gallery.

I started searching for a solution and one of then pointed to add the following line to the project manifest:
B4X:
AddPermission(android.permission.MANAGE_DOCUMENTS)

I did, but since the problem were still happening I searched a little more and found this other thread which instruct to add this other line to the project manifest:
B4X:
android.permission.WRITE_EXTERNAL_STORAGE

So I did, but the error EACCES (Permission denied) is still occurring.

Now my manifest editor shows the following lines:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(main, android:configChanges, "orientation|screenSize")
AddPermission(android.permission.MANAGE_DOCUMENTS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)

I need help to find the solution. What am I doing wrong or missing?

See below, log messages:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Success = true, Dir = ContentDir, FileName = content://media/external/images/media/44330
realPath = /storage/3061-3065/DCIM/Camera/20180609_095720.jpg
Error occurred on line: 43 (Main)
java.io.FileNotFoundException: /storage/3061-3065/DCIM/Camera/20180609_095720.jpg: open failed: EACCES (Permission denied)​


Regards,
Fernando
 

walterf25

Expert
Licensed User
Longtime User
Hello guys,

I'm trying Erel's test app (1.zip file from this thread, page 2) and having Permission Denied when choosing a photo from photo Gallery.

I started searching for a solution and one of then pointed to add the following line to the project manifest:
B4X:
AddPermission(android.permission.MANAGE_DOCUMENTS)

I did, but since the problem were still happening I searched a little more and found this other thread which instruct to add this other line to the project manifest:
B4X:
android.permission.WRITE_EXTERNAL_STORAGE

So I did, but the error EACCES (Permission denied) is still occurring.

Now my manifest editor shows the following lines:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(main, android:configChanges, "orientation|screenSize")
AddPermission(android.permission.MANAGE_DOCUMENTS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)

I need help to find the solution. What am I doing wrong or missing?

See below, log messages:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
sending message to waiting queue (OnActivityResult)
running waiting messages (1)
Success = true, Dir = ContentDir, FileName = content://media/external/images/media/44330
realPath = /storage/3061-3065/DCIM/Camera/20180609_095720.jpg
Error occurred on line: 43 (Main)
java.io.FileNotFoundException: /storage/3061-3065/DCIM/Camera/20180609_095720.jpg: open failed: EACCES (Permission denied)​


Regards,
Fernando
Do a search for RunTime Permissions in the forums

Regards,
Walter
 
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
This is an example from 2014. Before runtime permissions were introduced.
Have you changed the targetSdkVersion?
But target SDK in manifest is 26, isn't?
What else do I have to change?

AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetActivityAttribute(main, android:configChanges, "orientation|screenSize")
AddPermission(android.permission.MANAGE_DOCUMENTS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)
 
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
You wrote:


Have you modified the example in any way? I tested the example as-is and it works.

No... Just unzip it again right now and changed targed sdk from 14 to 26...

java.io.FileNotFoundException: /storage/3061-3065/DCIM/Camera/20180609_095720.jpg: open failed: EACCES (Permission denied)

It is worth to mention that the zipped version don't have any

AddPermission(android.permission.MANAGE_DOCUMENTS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.READ_EXTERNAL_STORAGE)


And I run it right now without them. Yesterday my manifest have them and the error was the same.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Just unzip it again right now and changed targed sdk from 14 to 26...
This is a huge change. We cannot guess which changes you made when you say that you run an example...
You must provide such information when you post questions.

I did, but since the problem were still happening I searched a little more and found this other thread which instruct to add this other line to the project manifest:
The tutorial doesn't instruct you to add the permission with the manifest editor. You need to go over the tutorial and understand how to handle runtime permissions. Watch the video tutorial.
 
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
This is a huge change. We cannot guess which changes you made when you say that you run an example...
You must provide such information when you post questions.

I'm telling you I DIDN'T change anything EXCEPT target SDK from 14 to 26...
I'm using Android 6 on my personal Samsung Galaxy J5.
 
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
@FERNANDO SILVEIRA I know sometimes things got complicated but you really need to read this

https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/

You need to add those permissions on your activity create or when you need to use them

Sample app worked after following addition
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult(permission As String, result As Boolean)
    If result = False Then
        Log("PERMISSION_READ_EXTERNAL_STORAGE negada")
        Return
    End If

    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult(permission As String, result As Boolean)
    If result = False Then
        Log("PERMISSION_WRITE_EXTERNAL_STORAGE negada")
        Return
    End If

Let's move on to the next pitfall... Who knows what we'll be facing... :mad::confused::(
 
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
Next chapter...

1) Noticed that GetPathFromContentResult = NULL when file name has "%2F" instead of "/".

Fixed by using FileName = FileName.Replace("%2F", "/").
Is this "conversion" always necessary?​

2) Picture succesfully selected if origin of ContentChooser is Photo Gallery. If, however, I select SD CARD ==> DCIM ==> CAMERA (which is where photo really is), I got this error:

java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/document/3061-3065%3ADCIM/Camera/20170210_130244.jpg from pid=11572, uid=10211 requires android.permission.MANAGE_DOCUMENTS, or grantUriPermission()

Which other authorization I have to get beyond these two? (find modified sample app attached).

B4X:
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult(permission As String, result As Boolean)
    If result = False Then
        Log("PERMISSION_READ_EXTERNAL_STORAGE negada")
        Return
    End If

    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For activity_PermissionResult(permission As String, result As Boolean)
    If result = False Then
        Log("PERMISSION_WRITE_EXTERNAL_STORAGE negada")
        Return
    End If
 

Attachments

  • 1.zip
    6.7 KB · Views: 360
Last edited:
Upvote 0

FERNANDO SILVEIRA

Active Member
Licensed User
In the IDE click on permissions list and see the permissions with * sign and make sure you already requested them at runtime

Click and then the result...

upload_2018-6-12_15-8-58.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
To avoid confusion to other developers I must say that almost everything that is written in this thread is incorrect.

No permission is required to access photos selected with ContentChooser. The main mistake is the usage of GetPathFromContentResult.

Search: https://www.b4x.com/search?query=GetPathFromContentResult

First search result: Get the path to media files returned from ContentChooser

As explained in that thread you shouldn't use this method at all unless you must find the file path. The correct solution is to avoid using this method.

The correct code is:
B4X:
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
   Log("Success = " & Success & ", Dir = " & Dir & ", FileName = " & FileName)
   If Success Then
     Activity.SetBackgroundImage(LoadBitmapSample(Dir, FileName, 100%x, 100%y))
   End If
End Sub

This thread is a good example of how not to ask a question.

1. The OP writes that he runs the example as-is but he actually changed the targetSdkVersion. Took 5 posts to find it out.
2. The relevant code that throws the error was never posted.
3. The reason for using ContentChooser was never explained. If it was explained then we could have immediately provide the correct solution.
4. A simple search for the main method used would have revealed that it should not be used.

All developers can ask as many questions as they like. However you do need to post them in such way that doesn't waste time and energy of other developers trying to help you.
 
Last edited:
Upvote 0
Status
Not open for further replies.
Top