Disable home button in android toddler app?
I think you're right regarding the home screen replacement. Toddler Lock I know doesn't override the home button, because (at least on my LG GW620) while in Toddle Lock holding the home button brings up the ALT-TAB type menu - which then tends to crash the phone.
There is a home screen replacement app available, with source code, on the android dev site:
http://developer.android.com/resources/samples/Home/index.html
EDIT: also, ADW.Launcher:
http://code.google.com/p/adw-launcher-android/
Android - How can I disable home button temporarily and recreate what Car Home and Toddler Lock have done?
hackbod is essentially correct. I have gotten much of the desired behavior by
- Make a "capture home key" activity
as described in the question. This
is not the main activity of the
program. - In the manifest, disable it.
- In the app, enable the "capture home
key" activity when you want the home
capture to happen, and disable it
when you want to exit.
The only question is what the capture home key activity should actually do. In my case, I needed it to just go to the start of the app... so it manufactures a CATEGORY_HOME intent, tests that it resolves correctly, and if so forwards on to the app. If it doesn't resolve correctly, it notifies the user, waits for the user to be ready, and then uses that intent. This way if the user chooses your app but doesn't make it default, he'll get prompted again.
How to disable Home and other system buttons in Android?
First of, please think long and hard if you really want to disable the Home
button or any other button for that matter (e.g. the Back
button), this is not something that should be done (at least most of the times, this is a bad design). I can speak only for myself, but if I downloaded an app that doesn't let me do something like clicking an OS button, the next thing I do is uninstall that app and leave a very bad review. I also believe that your app will not be featured on the App Store.
Now...
Notice that MX Player
is asking permission to draw on top of other applications:
Since you cannot override the Home
button on Android
device (at least no in the latest OS versions). MX Player
draws itself on top of your launcher when you "lock" the app and clicks on the Home
button.
To see an example of that is a bit more simple and straight forward to understand, you can see the Facebook Messenger App.
As I was asked to provide some more info about MX Player Status Bar
and Navigation Bar
"overriding", I'm editing my answer to include these topics too.
First thing first, MX Player is using Immersive Full-Screen Mode (DevBytes Video) on KitKat
.
Android 4.4 (API Level 19) introduces a new SYSTEM_UI_FLAG_IMMERSIVE flag for setSystemUiVisibility() that lets your app go truly "full screen." This flag, when combined with the SYSTEM_UI_FLAG_HIDE_NAVIGATION and SYSTEM_UI_FLAG_FULLSCREEN flags, hides the navigation and status bars and lets your app capture all touch events on the screen.
When immersive full-screen mode is enabled, your activity continues to receive all touch events. The user can reveal the system bars with an inward swipe along the region where the system bars normally appear. This clears the SYSTEM_UI_FLAG_HIDE_NAVIGATION flag (and the SYSTEM_UI_FLAG_FULLSCREEN flag, if applied) so the system bars become visible. This also triggers your View.OnSystemUiVisibilityChangeListener, if set. However, if you'd like the system bars to automatically hide again after a few moments, you can instead use the SYSTEM_UI_FLAG_IMMERSIVE_STICKY flag. Note that the "sticky" version of the flag doesn't trigger any listeners, as system bars temporarily shown in this mode are in a transient state.
Second: Hiding the Status Bar
Third: Hiding the Navigation Bar
Please note that although using immersive full screen is only for KitKat
, hiding the Status Bar
and Navigation Bar
is not only for KitKat
.
I don't have much to say about the 2nd and 3rd, You get the idea I believe, it's a fast read in any case. Just make sure you pay close attention to View.OnSystemUiVisibilityChangeListener.
I added a Gist that explains what I meant, it's not complete and needs some fixing but you'll get the idea. https://gist.github.com/Epsiloni/8303531
Disabling 'home' button in android for pattern lock app
Try this code
Override the below method in your Activity,
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
And handle the key event
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.i("Home Button","Clicked Home button");
}
return false;
}
How to disable the home key
Use this method to disable the Home key in android
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
How to manage/disable home button on Android 4.0?
There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. The home button is the one sure shot way to be able to leave any app.
In short, no it's not possible, and even if it were, it is a serious disruption in what a user expects out of an app's behavior. You will have to go with making your app into a launcher if you want to achieve this.
Related Topics
Assign Width to Half Available Screen Width Declaratively
Error:Unexpected Lock Protocol Found in Lock File. Expected 3, Found 0
On Android 8.1 API 27 Notification Does Not Display
How to Make an Intent with Multiple Actions
Android Webview, Scaling Image to Fit the Screen
Android Hello, Gallery Tutorial -- "R.Styleable Cannot Be Resolved"
Android Gridview Draw Dividers
Avoiding Content Type Issues When Downloading a File via Browser on Android
Recycler View Showing Single Item
Android Quotes Within an SQL Query String
Java.Lang.Securityexception: !@Too Many Alarms (500) Registered from Pid 10790 Uid 10206
How to Combine Bottomappbar + Fab with Bottomnavigationview
Android: When Is Oncreateoptionsmenu Called During Activity Lifecycle
Best Way to Update Data with a Recyclerview Adapter
Android Edittext, Soft Keyboard Show/Hide Event
How to Combine Multiple Images into a Single Image in Android