Android Question Denied permission SDK 23+

rscheel

Well-Known Member
Licensed User
Longtime User
Please help with this, any solution for this without changing android: targetSdkVersion = "22"

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="24"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
<uses-permission
  android:name="android.permission.READ_EXTERNAL_STORAGE"
  android:maxSdkVersion="18" />
    )


B4X:
ImageView1.Bitmap = LoadBitmap(File.DirRootExternal & "/Download", "alexandra.gif" )

Captura.PNG
 

rscheel

Well-Known Member
Licensed User
Longtime User
I'm trying to understand this tutorial but failed to implement it.

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

B4X:
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
   If Permission = rp.PERMISSION_READ_EXTERNAL_STORAGE Then

   End If
End Su

I do not understand this part.

B4X:
If <user has already approved> Or <older device> Then
Activity_PermissionResult (Permission, True)
Else
ShowDialog
Activity_PermissionsResult (Permission, Dialog result)
End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
One piece of advise, just stay with SDK < 23, the new permissions scheme might become a problem in some cases.
I don't agree. There aren't any known issues with runtime permissions...

The code posted in the first post is wrong. You should use RuntimePermissions.GetSafeDirDefault instead of File.DirRootExternal. See the tutorial.

You don't need to handle any permission in this case.
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
I don't agree. There aren't any known issues with runtime permissions...

The code posted in the first post is wrong. You should use RuntimePermissions.GetSafeDirDefault instead of File.DirRootExternal. See the tutorial.

You don't need to handle any permission in this case.

What you said back at me folder in the app and need to return the external memory device, not if I'm doing wrong.

B4X:
ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal(""), "Download/alexandra.gif")

Captura.PNG
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are some when you have code in Activity_Resume, the app doesn't look clean when it starts.
As I said I'm not familiar with any report of an issue with runtime permissions. For further discussion please start a new thread.

The code should be:
B4X:
ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal("Download"), "alexandra.gif"))

Or:
B4X:
ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal(""), "alexandra.gif"))
 
Last edited:
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
As I said I'm not familiar with any report of an issue with runtime permissions. For further discussion please start a new thread.

The code should be:
B4X:
ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal("Download"), "alexandra.gif"))

Or:
B4X:
ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal(""), "alexandra.gif"))

In both cases I have the same problem, to access the internal phone storage, as you can realize the images in both cases you can access the folder of the application and not the route to which I wish to enter the Blast of memory, in this case a solution could be to save the image file in the application folder.

But this I still can not see how to enter the external storage.

It should be noted that estou using Android 6.0.1.

B4X:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.devweb.cl.ofert/files/alexandra.gif: open failed: ENOENT (No such file or directory)

Captura2.PNG
Captura1.PNG
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
Please post the code and the logs as text instead of screenshots.

Where is the code that saves alexandra.gif to rp.GetSafeDirDefaultExternal("Download")?

Dear Erel leave test code.

B4X:
#Region  Project Attributes
    #ApplicationLabel: Prueba Carga Imagen
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim rp As RuntimePermissions
End Sub

Sub Globals
    Private ImageView1 As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("Layout1")
    '**** The Download folder is the default folder that brings Android to download is in the external storage of the phone, not in the external sd card.****
    ImageView1.Initialize("ImageView1")
    'ImageView1.Bitmap = LoadBitmap(File.DirRootExternal & "/Download", "alexandra.gif" ) 'This line works with the api 22 maximum.
    Log(rp.GetAllSafeDirsExternal(""))
    ImageView1.Bitmap = LoadBitmap(rp.GetSafeDirDefaultExternal("Download"), "alexandra.gif") 'This line does not work with api 23+.
    ImageView1.Gravity = Gravity.FILL
    Activity.AddView(ImageView1,10dip, 10dip, 100%x, 100%y)

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
With Api 23 you need to use the runtimePermission-System of Android 6


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim sdcardEnabled As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    sdcardEnabled = False
End Sub
Sub Activity_Resume
    If sdcardEnabled = False Then
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
  If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
        If Result Then
            sdcardEnabled = False
            Log("You NOW can write to File.DirRootExternal")      
             File.WriteString(File.DirRootExternal, "String.txt", _
        "This is some string" & CRLF & "and this is another one.")
        End If
  End If
End Sub

Additional you get asked by @Erel
Where is the code that saves alexandra.gif to rp.GetSafeDirDefaultExternal("Download")?

Especially for THIS you need to use the Runtimepermissionsystem to WRITE to the External SDCARD
 

Attachments

  • RuntimePermissionEx.zip
    7 KB · Views: 265
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
With Api 23 you need to use the runtimePermission-System of Android 6


B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private rp As RuntimePermissions
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim sdcardEnabled As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    sdcardEnabled = False
End Sub
Sub Activity_Resume
    If sdcardEnabled = False Then
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
  If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
        If Result Then
            sdcardEnabled = False
            Log("You NOW can write to File.DirRootExternal")     
             File.WriteString(File.DirRootExternal, "String.txt", _
        "This is some string" & CRLF & "and this is another one.")
        End If
  End If
End Sub

Additional you get asked by @Erel


Especially for THIS you need to use the Runtimepermissionsystem to WRITE to the External SDCARD


I'm just not keeping the image anywhere, I'm trying to read the image that is stored in Download.
 
Upvote 0

rscheel

Well-Known Member
Licensed User
Longtime User
Dear worked perfect, I share the code as to become, thanks them the time they are taken, will leave this example in the Spanish forum for others to access this information.

B4X:
Sub Process_Globals
    Dim rp As RuntimePermissions
End Sub

Sub Globals
    Private ImageView1 As ImageView
    Dim sdcardEnabled As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Activity.LoadLayout("Layout1")
    sdcardEnabled = False
End Sub

Sub Activity_Resume
    If sdcardEnabled = False Then
        rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
  If Permission = rp.PERMISSION_WRITE_EXTERNAL_STORAGE Then
        If Result Then
            sdcardEnabled = False
            Log("You NOW can write to File.DirRootExternal")     
            'File.WriteString(File.DirRootExternal, "String.txt", _
            '"This is some string" & CRLF & "and this is another one.")
            MuestraImagen
        End If
  End If
End Sub

Sub MuestraImagen
    ImageView1.Initialize("ImageView1")
    ImageView1.Bitmap = LoadBitmap(File.DirRootExternal & "/Download", "alexandra.gif" )
    ImageView1.Gravity = Gravity.FILL
    Activity.AddView(ImageView1,10dip, 10dip, 100%x, 100%y)
End Sub
 
Upvote 0
Top