0

I'm working on a smartphone rental service.

When the user unlocks the app

1) I would like to launch xxx app, instead of the android home screen

2) Would like to prevent the user from returning to the dashboard of the app (when they press the device home button)

Possible solution I could think of

1) Open the app before passing it to the customer

2) Prevent the app from returning to android home screen when device home button is press by redirecting it to the app dashboard when the home button event is triggered.

Detect home button press in android

This code only detects the event but didn't prevent the user from going back to the home screen.

@Override
protected void onUserLeaveHint()
{
    Log.d("onUserLeaveHint","Home button pressed");
    super.onUserLeaveHint();
}

Hope it's not something I need to do on the OS level.

Community
  • 1
  • 1
user1872384
  • 6,886
  • 11
  • 61
  • 103
  • 1
    The best solution is to make a custom ROM for the device, and build an app for that, so you can control all those above mentioned properties I guess. Again that kind of devs are best found on XDA forum :D XD – OBX Jan 21 '17 at 14:30
  • Why not create a custom launcher and set that to default. You can remove the default launcher app or instead lock the settings. – Kartik Sharma Jan 21 '17 at 15:25
  • How do I go about doing that? Mind to share? – user1872384 Jan 21 '17 at 15:37

1 Answers1

1

This actually something i've been working on for well over a year. It is not an easy task to accomplish nor is it going to be perfect, there is almost always a way out of the app without direct ROM access.

If you have access to all the hardware before the customer get's it you can use "Device Owner/Provisioning" which makes it much easier

https://source.android.com/devices/tech/admin/provision.html

Then with device owner you can use "Screen Pinning" without user prompting as well as disable specific apps etc.

https://developer.android.com/about/versions/android-5.0.html#ScreenPinning

Other than these, a recommended way is to

  1. Request "App Usage Access" when starting the app (Settings>Security) This will allow you to get the current "top" package, i.e. which app is running

  2. Start a service which periodically checks the top app to check if it != the allowed app

  3. If it is not your allowed app, then resume focus on your app

Of course there is other bits to consider, blocking of status bar (drawing an invisible view on top works well), prevention of access to system dialogues, requesting of "Device Admin" such that you can prevent uninstall of the main app without permission etc.

Broak
  • 4,161
  • 4
  • 31
  • 54
  • @user1872384 It's certainly given me many hours of pain and frustration but you will be able to get very close if you put all of these things together! Good luck and feel free to contact me if you need any more info :) – Broak Jan 21 '17 at 17:38