Disable home button and recent apps button in android application - android

I need to disable home button and recent apps button in my application since the activity opened which takes information is required and cannot leave empty

You can look for kiosk mode but that will require special permission (device admin permission) to activate.
you can also try "startLockTask()" in activity onCreate that will create a pinned screen

Related

How to prevent user's from returning to the android home screen?

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.
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.

What can I do to protect my launcher from exit?

I'm developing a home replacement application for kids. The user can't exit from the app (for example to open another application such as Settings) without a password.
What can I do to obtain this behavior?
I guess:
I should block the back button (done).
I should block the "recent apps" button (done but it's unstable)
I should block the access to the notification bar (is that possible? How?)
...?
I have spent the last 6 months developing this kind of application. The sad answer is, none of the above is fully possible. Android does not allow an application to meddle with things like notification bar, HOME Button or factory-reset resistance.
The only way to ensure you will be able to control all these things is to have a system signature, but it is only granted by the manufacturer for a selected phone model.
You can also try rooting the phone and meddling with the system config files directly, but it is rather dangerous.
You can hide the notification bar by using
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
With these the activity goes on fullscreen and should hide the notification bar.
However this works only for activity where you use it, so if you want to make it work for he entire app i suggeste you to put this inside the onCreate of a class that extends Activity and then make all of your activity extends this class.

Reset default launcher when app is closed

I have created a children's app that has a child lock using a custom launcher, however I have one small problem. When the app is closed and the home button is pressed the dialog to select the default launcher is displayed. Is there are way to reset the default launcher when the app is closed?
You cannot make any particular app be the default. However, you could use PackageManager and setComponentEnabledSetting(), to disable your activity that has the HOME category. Re-enable that when the user wants to have the choice of using your home screen again.

Unset default home screen from code

I'm trying to unset the default home screen programatically. My app is defined as home in manifest but if the user select the phone home screen as default (in the dialog to select the home screen) i cannot set my app as home again.
If the user select my app as home screen as default (with the checkbox "set as default") i have only to do:
clearPackagePreferredActivities("MypackageApp"); //from packagemanager
Then the selector appears again. But I don't know how to do for the dialog to select the current home screen appears again (when the user select the phone home screen as default) . I have tryed this:
clearPackagePreferredActivities("com.android.launcher"); //from packagemanager
But i obtain an error:
java.lang.security.exception Neither user * nor current process has android.permission.SET_PREFERRED_APPLICATIONS. But i have defined this permission in my manifest app.
I'm trying to unset the default home screen programatically.
Fortunately, this is not possible, for obvious security reasons.
My app is defined as home in manifest but if the user select the phone home screen as default (in the dialog to select the home screen) i cannot set my app as home again.
The user who switched back to a different home screen would consider this to be a very good thing.
But i have defined this permission in my manifest app.
You can only hold that permission if your application is signed by the same signing key as was used to sign the firmware.

Hide application from menu and show when we want to

I want to hide my app from main menu, when user want to, s/he can see their app.
To hide the app I've removed the launcher category, and for now the app get hidden but now I don't understand how can the user launch the app. I've read somewhere that using a key combination (on the DialerPad) one can show the main screen of activity. How is this done?
Any other ideas of launcher an app when a launcher is not present?
Yes you can hide your application icon but only on rooted devices or system signed apps.....the solution will be to first disable your application using shell command pm disable com.yourapppackagename and then enable it back using **pm enable com.yourapppackagename** this will first disable your app removing app icon from device and then enabling back your app will bring back the app icon only in device menu and not on homescreen. if you want to disable and then enable on user choice then you may create a toggle button such as when off then disable your app and when on then enable your app.It will definatly work i have already worked on something similar

Categories

Resources