I have developed a large (2K+ lines in Main and 6 service modules) app which runs on a smart watch under Android 5.1. Its part of a 2,500 active users system running through MQTT and all works really well including the servers and API written in B4J - so a HUGE thank you for your AWESOME software and libraries!
One of the trickiest bits was getting the physical buttons to be a part of my app not launching other apps, which was solved using the KIOSK approach and simple Java to trap the key presses and stop them being forwarded (extract of the code below - the full code times the presses for long and short events as well as cancels plus a myriad of other non relevant things). The watch has 3 buttons, 2 respond with key-presses and the other is the HOME button. All this works fine once the app is locked / screen pinned.
I am now porting to a different watch which has 4 buttons. One is HOME as above, one responds exactly the same as in the previous watch returning a key code of 4, the other two however NEVER return a keypress event - either from Java or Activity_KeyPress - they DO launch two apps, a heart monitor and compass app. If I lock the app / screen pinned then they are blocked and I get the toast about screen pining. BUT I cannot get the keypress event into my app.
I tried looking at the logs and found these events in there:
I am struggling trying to find a way to get these key presses into my app. All I need is to know they have been pressed and ideally check if they are held for a period. I have searched through and tried all the relevant examples I can find on the forum. Do you have any suggestions?
Many thanks
Harry
One of the trickiest bits was getting the physical buttons to be a part of my app not launching other apps, which was solved using the KIOSK approach and simple Java to trap the key presses and stop them being forwarded (extract of the code below - the full code times the presses for long and short events as well as cancels plus a myriad of other non relevant things). The watch has 3 buttons, 2 respond with key-presses and the other is the HOME button. All this works fine once the app is locked / screen pinned.
B4X:
Sub keyrelease(kv As Int) 'ignore
Log("rels -> " & kv)
End Sub
Sub keypush(kv As Int) 'ignore
Log("push -> " & kv)
End Sub
#If JAVA
import android.view.*;
public boolean _onkeydown (int keyCode, android.view.KeyEvent event){
//BA.Log("Down = " + keyCode);
if (processBA.subExists("keypush")) {
processBA.raiseEvent(null,"keypush",keyCode);
return true;
}
return true;
}
public boolean _onkeyup (int keyCode, android.view.KeyEvent event){
//BA.Log("Up = " + keyCode);
if (processBA.subExists("keyrelease")) {
processBA.raiseEvent(null,"keyrelease",keyCode);
return true;
}
return true;
}
#End IF
#End Region
I am now porting to a different watch which has 4 buttons. One is HOME as above, one responds exactly the same as in the previous watch returning a key code of 4, the other two however NEVER return a keypress event - either from Java or Activity_KeyPress - they DO launch two apps, a heart monitor and compass app. If I lock the app / screen pinned then they are blocked and I get the toast about screen pining. BUT I cannot get the keypress event into my app.
I tried looking at the logs and found these events in there:
Calling a method in the system process without a qualified user: android.app.ContextImpl.startActivity:1349 android.app.ContextImpl.startActivity:1338 com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeDispatching:2946 com.android.server.wm.InputMonitor.interceptKeyBeforeDispatching:574 com.android.server.input.InputManagerService.interceptKeyBeforeDispatching:1547
START u0 {flg=0x10000000 cmp=com.jxtek.compass/.MainActivity} from uid 1000 from pid 727 on display 0
ACT-NEW_INTENT handled : 0 / NewIntentData{intents=[Intent { flg=0x10800000 cmp=com.jxtek.compass/.MainActivity }] token=android.os.BinderProxy@3584903d}
Calling a method in the system process without a qualified user: android.app.ContextImpl.startActivity:1349 android.app.ContextImpl.startActivity:1338 com.android.internal.policy.impl.PhoneWindowManager.interceptKeyBeforeDispatching:2964 com.android.server.wm.InputMonitor.interceptKeyBeforeDispatching:574 com.android.server.input.InputManagerService.interceptKeyBeforeDispatching:1547
START u0 {flg=0x10000000 cmp=com.jx.heart/.activity.HeartActivity} from uid 1000 from pid 727 on display 0
I am struggling trying to find a way to get these key presses into my app. All I need is to know they have been pressed and ideally check if they are held for a period. I have searched through and tried all the relevant examples I can find on the forum. Do you have any suggestions?
Many thanks
Harry