Android Question open failed: EACCES (Permission denied)

Discussion in 'Android Questions' started by FERNANDO SILVEIRA, Jun 12, 2018.

Thread Status:
Not open for further replies.
  1. FERNANDO SILVEIRA

    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:
    Code:
    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:
    Code:
    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:
    Code:
    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
     
  2. PassionDEV

    PassionDEV Active Member Licensed User

    you need to request runtime permission have you done this already ?

    in permission list the permission marked with a star need a run time permission on the new target sdk
     
    FERNANDO SILVEIRA likes this.
  3. walterf25

    walterf25 Well-Known Member Licensed User

    Do a search for RunTime Permissions in the forums

    Regards,
    Walter
     
    FERNANDO SILVEIRA likes this.
  4. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Hi Walter, I just trying to run the sample app... I think Erel took care of this since he built the test app I'm trying to run.

    But, I'll read a bit more on Runtime Permission,

    Thank you.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    This is an example from 2014. Before runtime permissions were introduced.
    Have you changed the targetSdkVersion?
     
  6. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    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)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    You wrote:
    Have you modified the example in any way? I tested the example as-is and it works.
     
  8. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    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.
     
  9. PassionDEV

    PassionDEV Active Member Licensed User

    FERNANDO SILVEIRA likes this.
  10. Erel

    Erel Administrator Staff 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.

    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.
     
  11. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    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.
     
  12. PassionDEV

    PassionDEV Active Member Licensed User

    FERNANDO SILVEIRA likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    I know. As I wrote changing the targetSdkVersion is a huge change. Not something that can be done without mentioning it in your question.
     
    DonManfred and PassionDEV like this.
  14. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    PassionDEV likes this.
  15. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Sample app worked after following addition
    Code:
    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::(
     
  16. FERNANDO SILVEIRA

    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).

    Code:
    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
     

    Attached Files:

    • 1.zip
      File size:
      6.7 KB
      Views:
      83
    Last edited: Jun 12, 2018
  17. PassionDEV

    PassionDEV 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
     
  18. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Click and then the result...

    upload_2018-6-12_15-8-58.png
     
  19. Erel

    Erel Administrator Staff Member Licensed 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:
    Code:
    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%x100%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: Jun 13, 2018
    Computersmith64 and DonManfred like this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice