grafsoft

Well-Known Member
Licensed User
Longtime User
Hi,

it always crashes in the sub init,

B4X:
    Log ("RuntimePermissions")
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
    rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
' *** crashes next line
    rp.CheckAndRequest(rp.PERMISSION_WRITE_CONTACTS)
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
    Log ("checknotification")
    checknotification
    Log ("STT.Initialize")
    STT.Initialize("STT", File.DirInternal&"/"& model_folder_name)

The error message:

** Activity (main) Pause event (activity is not paused). **
throwing b4a uncaught exception
notifyKeepScreenOnChanged: keepScreenOn=false
*** mainpage: B4XPage_Appear
setSurface called with nullptr
setSurface called with nullptr
Error occurred on line: 145 (B4XMainPage)
java.lang.Exception: array not expected...

But when I put this line

B4X:
STT.Initialize("STT", File.DirInternal&"/"& model_folder_name)

further up, above the CheckAndRequest block, I get

Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 23977 (anita.phone), pid 23977 (anita.phone)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
...

Therefore I think the real error is further up the line. I could start the program before, but when I tried the (now uncommented) changes in the manifest editor, the problems began. I know I am asking a lot, but could someone take a look at this mess?

I had to remove the file model.zip from b4a/files, or the zip-file would have become too big. The file can be downloaded here: https://www.b4x.com/android/forum/threads/speechtotext-continuous-offline-voice-recognition.134857/
 

Attachments

  • Project.zip
    24.5 KB · Views: 64
Solution
Problem solved! I put the CheckAndRequest at the very start of the program and added sleep statements.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Log ("create")
    Root = Root1
    Root.LoadLayout("MainPage")
    
    Log ("RuntimePermissions")
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_WRITE_CONTACTS)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Sleep (0)
    rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
    Sleep (0)

grafsoft

Well-Known Member
Licensed User
Longtime User
Problem solved! I put the CheckAndRequest at the very start of the program and added sleep statements.

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Log ("create")
    Root = Root1
    Root.LoadLayout("MainPage")
    
    Log ("RuntimePermissions")
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_WRITE_CONTACTS)
    Sleep (0)
    rp.CheckAndRequest(rp.PERMISSION_CALL_PHONE)
    Sleep (0)
    rp.CheckAndRequest (rp.PERMISSION_READ_PHONE_STATE)
    Sleep (0)
 
Upvote 0
Solution

agraham

Expert
Licensed User
Longtime User
You would be better doing it properly with WaitFor
B4X:
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
 rp.CheckAndRequest(rp.PERMISSION_READ_CONTACTS)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
...
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Check the way Erel does:

 
Upvote 0
Top