How to program the system back button on an Android device

Just starting out? Need help? Post your questions and find answers here.
yves86
Posts: 3
Joined: Fri Dec 20, 2019 2:35 pm

How to program the system back button on an Android device

Post by yves86 »

Hi,
I want to include in an Android app, the detection from the system back button on an Android device.

Does any one have an idea ?

Thanks
Windows 11 x64
Purebasic 6.04, Spiderbasic 2.51
hoerbie
Posts: 137
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: How to program the system back button on an Android device

Post by hoerbie »

Have a look in the docs on BindCordovaEvent("backbutton", @yourcallback())
yves86
Posts: 3
Joined: Fri Dec 20, 2019 2:35 pm

Re: How to program the system back button on an Android device

Post by yves86 »

Thanks hoerbie,

I have find this topic /
viewtopic.php?p=5398&hilit=BindCordovaEvent#p5398

But its doesnt work !
Windows 11 x64
Purebasic 6.04, Spiderbasic 2.51
hoerbie
Posts: 137
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: How to program the system back button on an Android device

Post by hoerbie »

Hi,
I can check my codes next week, when I‘m back in office. But until now I only use this to disable all buttons on Android.
hoerbie
Posts: 137
Joined: Sun Mar 17, 2019 5:51 pm
Location: DE/BY/MUC

Re: How to program the system back button on an Android device

Post by hoerbie »

Hi,
please try something like the following:

Code: Select all

Procedure BindCordovaEvent(Event.s, *Callback)
  !document.addEventListener(v_event, p_callback);
EndProcedure   

Procedure back_event()
  Debug "CordovaEvent: back"
EndProcedure
Procedure volumeup_event()
  Debug "CordovaEvent: volume up"
EndProcedure
Procedure volumedown_event()
  Debug "CordovaEvent: volume down"
EndProcedure
Procedure resume_event()
  Debug "CordovaEvent: resume"
EndProcedure
Procedure pause_event()
  Debug "CordovaEvent: pause"
EndProcedure

;only for Android:
BindCordovaEvent("backbutton", @back_event())
BindCordovaEvent("volumeupbutton", @volumeup_event())
BindCordovaEvent("volumedownbutton", @volumedown_event())

;for Android and iOS
BindCordovaEvent("resume", @resume_event())
BindCordovaEvent("pause", @pause_event())
Can't test it now, but this is copied from my sources, removed my code and changed to demo debug, so it should work this way.

On https://cordova.apache.org/docs/en/late ... vents.html you can find additional Cordova events.
yves86
Posts: 3
Joined: Fri Dec 20, 2019 2:35 pm

Re: How to program the system back button on an Android device

Post by yves86 »

Hi
Thanks hoerbi,

It's fine.
Windows 11 x64
Purebasic 6.04, Spiderbasic 2.51
Quin
Posts: 118
Joined: Wed Nov 08, 2023 4:38 pm

Re: How to program the system back button on an Android device

Post by Quin »

Just tested on my phone (a Pixel 7 pro) and it worked flawlessly. Thanks a ton for this!
hoerbie wrote: Mon Mar 18, 2024 7:07 pm Hi,
please try something like the following:

Code: Select all

Procedure BindCordovaEvent(Event.s, *Callback)
  !document.addEventListener(v_event, p_callback);
EndProcedure   

Procedure back_event()
  Debug "CordovaEvent: back"
EndProcedure
Procedure volumeup_event()
  Debug "CordovaEvent: volume up"
EndProcedure
Procedure volumedown_event()
  Debug "CordovaEvent: volume down"
EndProcedure
Procedure resume_event()
  Debug "CordovaEvent: resume"
EndProcedure
Procedure pause_event()
  Debug "CordovaEvent: pause"
EndProcedure

;only for Android:
BindCordovaEvent("backbutton", @back_event())
BindCordovaEvent("volumeupbutton", @volumeup_event())
BindCordovaEvent("volumedownbutton", @volumedown_event())

;for Android and iOS
BindCordovaEvent("resume", @resume_event())
BindCordovaEvent("pause", @pause_event())
Can't test it now, but this is copied from my sources, removed my code and changed to demo debug, so it should work this way.

On https://cordova.apache.org/docs/en/late ... vents.html you can find additional Cordova events.
Post Reply