Reputation: 7147
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.
Upvotes: 0
Views: 1543
Reputation: 4187
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
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
Start a service which periodically checks the top app to check if it != the allowed app
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.
Upvotes: 1