Android Question old HTTPServerExample, permission at runtime, how?

a6000000

Member
Licensed User
Longtime User
old HTTPServerExample permission at runtime how?
https://www.b4x.com/android/forum/threads/embed-an-http-server-in-your-android-application.25984/


I add in manifest editor SDK 29 and permissions

AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.MOUNT_UNMOUNT_FILESYSTEMS)
AddPermission(android.permission.INTERNET)



and try in ServerService:

B4X:
Sub Server_HandleRequest (Request As ServletRequest, Response As ServletResponse)

      'add for permission:
    Public rp As RuntimePermissions
    rp.CheckAndRequest("READ_EXTERNAL_STORAGE")
    rp.CheckAndRequest("WRITE_EXTERNAL_STORAGE")
    rp.CheckAndRequest("ACCESS_FINE_LOCATION")
    rp.CheckAndRequest("INTERNET")
      'end add for permission
  

    Try
        Log("Client: " & Request.RemoteAddress)
        Log(Request.RequestURI) 'handle the request based on the URL
        Select True
            Case Request.RequestURI = "/"
                HandleMainPage (Response)
            Case Request.RequestURI.StartsWith("/list/")
                HandleList (Request, Response)
            Case Request.RequestURI.StartsWith("/download/")
                SetContentType(Request.RequestURI, Response)
                Response.SendFile("", DecodePath(Request.RequestURI.SubString(9)))
            Case Request.RequestURI.StartsWith("/upload/")
                HandleUpload(Request, Response)
            Case Else
                'send a file as a response (this section is enough in order to host a site)
                SetContentType(Request.RequestURI, Response)
                Response.SendFile(File.DirAssets, DecodePath(Request.RequestURI.SubString(1)))
        End Select
    Catch
        Response.Status = 500
        Log("Error serving request: " & LastException)
        Response.SendString("Error serving request: " & LastException)
    End Try
End Sub


but Error
 
Top