I am developing an app
and I need to disable the home button or change his behavior on clicking a button
how can I do it?
I have already tried to use the onKeyDown event and other events
You cannot block the Home button from sending intent android.intent.category.HOME which switches to the launcher but you can set your window to be always on top so the launcher won't be shown.
Related
I am trying to make a launcher using flutter. I have made multiple screens for doing specific tasks like HomeScreen. AppDrawerScreen and so on. The problem I am facing is whenever I go to say AppDrawerScreen and press on the Home Button, I am not redirected to the HomeScreen. How can I handle this scenario?
I've had the same problem. I guess the only solution is to listen to the Home button, and there go to the first screen. there is a plugin called hardware_buttons, and about the Back button you can use the WillPopScope() widget.
You can achieve this by adding WidgetsBindingObserver mixing to your StatefulWidget class.
And then you can invoke didChangeAppLifecycleState() method where you can listen to the AppLifeCycleState changes like :
inactive
paused
resume and soon
But in your case since you want to navigate to HomeScreen when Android Home Button is pressed so you need to check if AppLifeCycleState.inactive is true (which means you have pressed the Android Home Button and app is running in background) and there you can add your code to Navigate to HomeScreen.
Also you can refer to this documentation for more information.
I am making an app exclusive for the tablet it was installed to. I wanted to put a restriction so that when the back button or home button is pressed the user will be prompted to enter a password and if the password is correct application be allowed to exit.
Overriding the back button is pretty easy, just override Activity.onBackPressed() to do whatever you want. Don't call super() or it will close the Activity!
Overriding the home button is more problematic. The only way to do so is to make your app a launcher. Then press home and select your app as the default launcher.
I'm not sure that this could be a good idea. You're "blocking" the user in this way. You can probably override the back button but you will not be able to override the home button (without making the app a launcher).
I did a sort of "kiosk" application and I had the same requirements. I ended up rooting the devices and using this Hide Bar application. The user was not able to go back, and the administrator had a button to enter, with a password, into the "admin panel". In this admin panel you can push a button to go to the launcher. From there you can, with a widget included into the Hide Bar app, restore the back and home buttons.
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html
May be this can help you for setting the passoward.
When using a floating view (TYPE_PRIORITY_PHONE) how can the Home button be intercepted?
This behaviour is demonstrated in Facebook's "chat heads" where a conversation (which isn't an Activity) is collapsed on a home button click.
You could poll the top running app, and determine when it changes. This will detect the first home press, but if the users is already on the home screen, you will not detect it.
I've an desktop widget, and inside it I have a settings button - when tap it, I launch an activity, where I can change widget settings. An activity is very simple, it has only few spinner, checkboxes, etc. and 2 button - OK and CANCEL.
And the biggest problem for me is, that I know how to launch activity from widget, but don't know how to "go back" to widget from activity - the only possible way is press the back button on the phone. But as u can see, I really need to have 2 buttons - OK and Cancel, as its looks much more natural for the user. What method I should use after pressing OK/Cancel button to turn an activity to background and widget to foreground?
try this
in onclicklistener of ok button call finish()
I have an Activity that keeps running after the HOME button is pressed (naturally) and of-course the focus is in the home screen, and when the running process ends i need to restore the focus on that activity.
Put a notification like GMail, Calendar, AppStore...