Android Question Char() encoding issue

Martin Beukes

Member
Licensed User
Longtime User
Greetings Peeps,

I have a weird issue with a specific piece of equipment. When I receive physical keyboard input the app is not converting it properly, but it works on most devices I have tested with. The code is probably going to make more sense than what I write here.

I listen for key inputs in Java Code:
B4X:
public boolean _onKeyDown(int KeyCode, KeyEvent event) {
        switch (KeyCode) {
 case 31:
            {      processBA.raiseEvent(null, "control_inputs", event.getUnicodeChar());
                return true;
            }
default:
            {      return true;
            }
        }


And I receive the inputs with this:
B4X:
Sub control_inputs(i As Int)
        If i = 99999 Then
            Starter.myInputCase = "u"
            myKeyTimer.Enabled = True
        Else
            'Log(i)
            Dim s As String = Chr(i)
            If Starter.myInputCase = "u" Then
                s = s.ToUpperCase
                Starter.myInputCase = ""
            End If
            If i <> 1 And i <> 2 Then
                Starter.myInputToken = Starter.myInputToken & s
            Else
                Starter.myInputToken = Starter.myInputToken & i
            End If
            
End Sub

I don't know why the device is not returning the proper ascii characters, I can only think it is some kind of encoding error and I don't know how to check it.

Thanks,
Martin
 

Martin Beukes

Member
Licensed User
Longtime User
Hi all, sorry, I have been afk.

What is happening at the moment on the device that will be used for production is I am getting Chinese characters. There is no android setting I can see that is wrong (not in Latin). On my phone (and about a dozen devices) it works fine.

Erel, i need to capture the keydown. I remember at the time of writing the origional code this was the only way to do what I needed. I will test the activity_keypress and see if it can do what I need.
 
Upvote 0

emexes

Expert
Licensed User
I mean 'a' or 'b' or 'c' or 'd' when that button was pressed on the physical keyboard
The way I'm reading the Java code, you are only responding to keycode 31, and so that key's corresponding Unicode character will be the only character you ever see.

What is also mildly suspicious is that the Java routine seems to swallow all keystroke events, rather than passing the unhandled keystrokes down the chain. Although I guess this could be reasonable if the app is a game.
 
Upvote 0
Top