Android Question Problem using RandomAcessFile 2.33

Roberto M. de Oliveira

Member
Licensed User
My program normally compiles on a Windows 7 32-bit PC, version B4A 9.80.
On a new PC, windows 10 32 bits, I installed the B4A 10.00, according to the installation guidance.

The compilation runs ok! and used AndroidX SDK.

When I run the program an error occurs when reading files (i'm using randomacessfile 2.33, encrypted object). All registers return empty!

I did one more test on the program and changed it to use the files structure from core 9.90.

The program started to work normally, but I would like to use encryption.

Can this provide a way to solve the problem?
 

DonManfred

Expert
Licensed User
Longtime User
When I run the program an error occurs when reading files
RandomAccessFile is working as it was in the past. Nothing has changed in RAF.

Where is the full error?

Best would be if you upload a small project which shows the problem.
 
Upvote 0

Roberto M. de Oliveira

Member
Licensed User
Thank you for your commitment, Don!

The program below presents the problem described.

Full Program ...:
#Region  Project Attributes
    #ApplicationLabel: GoTELEMED
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: Portrait
    #CanInstallToExternalStorage: False
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim p As PhoneIntents

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 Sair As Button
    Dim WEB_Address As EditText
    Dim Postos As ListView
    Dim IME1 As IME
    Dim RAF As RandomAccessFile
    Dim RP As RuntimePermissions
    
    Dim Diretorio, Password As String
    Dim DDNS_Postos As List

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

    Activity.LoadLayout("teste")
    Activity.Title="GoTELEMED Vs1.07"
    
    Password="ROMC Consultores"
    Diretorio="GoTELEMED"

    IME1.Initialize("")
    IME1.HideKeyboard

    'Solicitação de acesso à memoria
    RP.CheckAndRequest(RP.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = RP.PERMISSION_READ_EXTERNAL_STORAGE Then Log("PERMISSION_READ_EXTERNAL_STORAGE = " & Result)
    RP.CheckAndRequest(RP.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = RP.PERMISSION_WRITE_EXTERNAL_STORAGE Then Log("PERMISSION_WRITE_EXTERNAL_STORAGE = " & Result)

    Dim Config As Label
    Postos.Clear
    Postos.SingleLineLayout.ItemHeight=100
    Config= Postos.SingleLineLayout.Label
    Config.TextSize=16
    Config.TextColor=Colors.Black
    
    InicializarTratArqUser

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

'**********************************************************************************************
'
'**********************************************************************************************
Sub Activity_PermissionResult (Permission As String, Result As Boolean)

End Sub

'**********************************************************************************************
' Rotinas para recolher o teclado
'**********************************************************************************************
Sub Recolher_Teclado
    'A digitação do "ENTER" recolhe o teclado
'    Sleep(0)
    IME1.HideKeyboard
'    Recolher_BarNav
'    Sleep(0)
End Sub

'**********************************************************************************************
' Rotinas do modo imersivo da tela
'**********************************************************************************************
'Sub Recolher_BarNav
'    Activity_WindowFocusChanged(True)
'    Dim lv As LayoutValues = GetRealSize
'    Dim jo As JavaObject = Activity
'    jo.RunMethod("setBottom", Array(lv.Height))
'    jo.RunMethod("setRight", Array(lv.Width))
'    Activity.Height = lv.Height
'    Activity.Width = lv.Width
'End Sub

'Sub GetRealSize As LayoutValues
'    Dim lv As LayoutValues
'    Dim pb As Phone
'    If pb.SdkVersion >= 17 Then
'        Dim ctxt As JavaObject
'        ctxt.InitializeContext
'        Dim display As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window")).RunMethod("getDefaultDisplay", Null)
'        Dim point As JavaObject
'        point.InitializeNewInstance("android.graphics.Point", Null)
'        display.RunMethod("getRealSize", Array(point))
'        lv.Width = point.GetField("x")
'        lv.Height = point.GetField("y")
'    Else
'        lv.Width = 100%x
'        lv.Height = 100%y
'    End If
'    lv.Scale = 100dip / 100
'    Return lv
'End Sub

'Sub Activity_WindowFocusChanged(HasFocus As Boolean)
'    If HasFocus Then
'        Try
'            Dim jo As JavaObject = Activity
'            Sleep(300)
'            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
'        Catch
'            'Log(LastException) 'This can cause another error
'        End Try 'ignore
'       
'    End If
'End Sub
'
Sub WEB_Address_EnterPressed
    Dim i As Int, URL As String
    Recolher_Teclado
    If WEB_Address.Text.Length>2 Then
        Postos.AddSingleLine(NumberFormat(Postos.Size,2,0) & " " & WEB_Address.Text.ToLowerCase)
    Else
        If WEB_Address.Text.Length=2 And IsNumber(WEB_Address.Text) Then
            If WEB_Address.Text<=Postos.Size-1 And WEB_Address.Text>0 Then
                Postos.RemoveAt(WEB_Address.text)
            End If
        End If
    End If
    DDNS_Postos.Initialize
    For i=0 To Postos.Size-1
        URL=Postos.GetItem(i)
        If i>0 Then
            DDNS_Postos.Add(NumberFormat(i,2,0) & " " & URL.SubString(3))
        Else
            DDNS_Postos.Add(URL)
        End If
    Next
    Gravar_ArqArqGoTELEMED
    Ler_ArqArqGoTELEMED
End Sub

Sub Postos_ItemClick(No_Linha As Int, Valor As Object)
    Dim URL As String
    If No_Linha>0 Then
        URL=Postos.GetItem(No_Linha)
        StartActivity(p.OpenBrowser("http://" & URL.Substring(3) & ":6001"))
    End If
End Sub

Sub Sair_Click
    ExitApplication
End Sub

'**********************************************************************************************
' Tratamento de arquivos - Rotinas
'*********************************************************************************************
Sub InicializarTratArqUser
    If File.Exists(File.DirRootExternal,Diretorio & "/ArqGoTELEMED.dat")=False Then Criar_ArqArqGoTELEMED
    Log("Lendo arquivos ...")
    Ler_ArqArqGoTELEMED
    Log("Arquivo ArqGoTELEMED.dat lido!")
End Sub

Sub Criar_ArqArqGoTELEMED 'Cria o Arquivo de DDNS dos postos (rede)
    Dim Dia As String
    File.MakeDir(File.DirRootExternal,Diretorio)
    DDNS_Postos.Initialize
    Dia=DateTime.Date(DateTime.Now)
    Dia=Dia.SubString2(3,6) & Dia.SubString2(0,3) & Dia.SubString2(8,10)
    DDNS_Postos.Add("Arquivo criado em " & Dia & " " & DateTime.Time(DateTime.Now))
    Gravar_ArqArqGoTELEMED
    Log("Arquivo ArqGoTELEMED.dat Criado!")
End Sub

Sub Ler_ArqArqGoTELEMED
    LerArquivo(DDNS_Postos,Password,Diretorio & "/ArqGoTELEMED.dat")
    Postos.Clear
    For i=0 To DDNS_Postos.Size-1
        Postos.AddSingleLine(DDNS_Postos.Get(i))
    Next
End Sub

Sub Gravar_ArqArqGoTELEMED
    GravarArquivo(DDNS_Postos,Password,Diretorio & "/ArqGoTELEMED.dat")
End Sub

'**********************************************************************************************
' Tratamento de arquivos - Leitura e Gravação
'*********************************************************************************************
Sub LerArquivo(Dados As List,Senha As String,Arquivo As String)
    Dados.Initialize
    RAF.Initialize(File.DirRootExternal, Arquivo, False)
    Dados=RAF.ReadEncryptedObject(Senha, RAF.CurrentPosition)
    RAF.Close
End Sub

Sub GravarArquivo(Dados As List,Senha As String,Arquivo As String)
    RAF.Initialize(File.DirRootExternal, Arquivo, False)
    RAF.WriteEncryptedObject(Dados,Senha, RAF.CurrentPosition)
    RAF.Close
End Sub

'**********************************************************************************************
 
Upvote 0

Roberto M. de Oliveira

Member
Licensed User
I want to apologize for causing this misunderstanding.
I didn't include the full program package because is too much to send.
You can use the URL: "romc.ddns.net".

If you can still help me, I appreciate it.

The layout is attached with other program parts!
 

Attachments

  • teste.bal
    4.6 KB · Views: 111
  • Starter.zip
    3.8 KB · Views: 101
Upvote 0
Top