4

I'm writing an app for an Android tablet in Delphi XE7. I want to turn off home and back button so no one can leave the application. I have found many answers, but none refers to Delphi.

How can I achieve this in Delphi? What objects should I use? Which units I need to include?

Danilo Casa
  • 506
  • 1
  • 9
  • 18
Gpgerhard
  • 79
  • 1
  • 2
  • Please keep it in english as it will be easier for everyone to understand. – Nahuel Ianni Jan 12 '15 at 13:10
  • 4
    `I want to turn off home...` - Can you even disable the home button on an Android app? I would be very surprised if you could... – kobik Jan 12 '15 at 14:07
  • 1
    @David If your app is Point of Sale app or something similar, you may want to have it locked in. This is perfectly valid requirement, but not for general public, of course. – Dalija Prasnikar Jan 12 '15 at 14:13
  • 2
    @David, an app for children which controlled by their parents for example could be also legit in this case... – kobik Jan 12 '15 at 14:14
  • 2
    http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key – Dalija Prasnikar Jan 12 '15 at 14:14
  • @kobik A restart would defeat that – David Heffernan Jan 12 '15 at 14:20
  • 1
    @David only if kids know how to restart :) – Dalija Prasnikar Jan 12 '15 at 14:25
  • I'm almost sure this is not possible. You see even if you disable the "Home" and "Back" buttons in your app, the user can drag the notification bar down and switch applications then use the "Home" button from there. Also I'm pretty sure you can't disable those buttons systemwide. And how about the "Switch task " button. – mg30rg Jan 12 '15 at 14:25
  • 1
    @Dalija I guess you don't have kids!! – David Heffernan Jan 12 '15 at 14:26
  • 2
    @David only three... I didn't say that you can use that method forever... – Dalija Prasnikar Jan 12 '15 at 14:28
  • Reconsidering the case, **I strongly hope** that is not possible. It would be a massive bug in the Android system and as one, even if it is possible somehow, a later fix would disable your "solution". – mg30rg Jan 12 '15 at 14:28
  • 1
    @David, "A restart would defeat that" I'm pretty sure you could set an app to automatically start on Android (after restart) - given the right permissions. Take a look at this nice app: [Kids Zone Parental Controls](https://play.google.com/store/apps/details?id=com.ootpapps.kids.zone.app.lock&hl=en) – kobik Jan 12 '15 at 14:41
  • 1
    @kobik that would be a pretty useless device – David Heffernan Jan 12 '15 at 14:46
  • 1
    With all those Google's ways to get a dollar, Delphi users still want to create ransomware... Just amazing! – Free Consulting Jan 12 '15 at 14:46
  • 1
    I can think of plenty reasons why one would wish to disable these buttons, but I see no reason why Android would make it available. – Jerry Dodge Jan 12 '15 at 14:48
  • 1
    @David, well if the device belongs to my child and I do want to restrict him, I think it is legit. in any case I just gave an example where this can be useful. I don't think the OP deserves down-votes. it's a [good question](http://stackoverflow.com/questions/3898876/how-to-disable-the-home-key) actually. – kobik Jan 12 '15 at 14:52

1 Answers1

10

From documentation

Using the Android Device's Back Button

To make your application handle when users press the Back button on their Android device, add an event handler to your form for OnKeyUp, and use the following code within your event handler: In Delphi:

if Key = vkHardwareBack then
begin
  // Do whatever you want to do here
  Key := 0; // Set Key = 0 if you want to prevent the default action
end;
RBA
  • 12,337
  • 16
  • 79
  • 126