I am working on an application in which user should be able to use only one application,
he should not be able to switch application using HOME button,
the app. should be closed only when user presses the close button..
I have managed to override return button, don't know how to disable HOME button.
This is not possible to disable the Home Button in android When application is in the background because it might some application always disable the home button if it's possible. So this is the reason developer can't disable the home button when app in background. But In the Activity, you can intercept the home button.
In Activity you can disable the Home key in android. It work till Android 3.x only.
#Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
TGMCians is right.
Android will not let an activity and its services run completely alone on your device.
Using Override you can capture button clicks (home, back and menu) when your activity is in the foreground. If an activity/service has full control from the background you would not be able to switch for an incoming sms, e-mails, phone calls, etc either.
Personally I think its dangerous to override the home and back button together, if the activity hangs at some point, you can not get out of the app unless you restart the phone.
Personally, I do override the back key for exit, or return to main screen events, but leave the home button alone.
This is not possible using code at all on iOS, ever.
One usage of HOME button is for emergency situation.
Any house, apartment ... they all have an emergency method, like emergency door (exit), glass breaker (axe, bat ...); it saves life.
Similarly, on Android/iOS phone, HOME button saves users' lives (well, kind of). If HOME button is dead, the phone is considered dead as well as required an instant reboot for refresh. The button was designed for such a purpose, so that developers can't messed-up with everything.
Personally, I'm kinda of being thankful for Android/iOS framework team and whoever thought of this situation on HOME button. It saves my development so many times. I suggest you should think and consider the worst case possible if HOME button is not working in your app; for example, app fails to function as normal, HOME is disabled, so how to back to HOME screen, how to switch to other apps?...
The code provided by TGMCians is not working on 4.0+.
In case, you are working on Android framework, such as building ROMs, building frameworks for manufacturers, ... grep the source code with KEY_HOME and trace inner-depth to find how it works and disable it.
actually, it is possible to block the home button using the next methods:
use of security holes, at least on old android versions. this is done on some locker apps. i think some still work even on newer android versions, but it's a risk and it might be buggy on some devices. i know that "widgetLocker" and "Picture Password Lockscreen" try out those holes. i'm not sure how well they work now with them. best solution of becoming a lockscreen is #2 .
make your app a launcher app, which will handle the home button (user must confirm it of course). an example of such an app is "MagicLocker" , and in fact any launcher app...
using a rooted device. i have no idea how to do it, but i think it's very possible.
not quite a blocking method, but you could have your app full screen and on top (using the TYPE_SYSTEM_ALERT window layout type) , so home button won't be captured, but the user won't see what's going on behind your app. the downside is that any other button won't be captured by your app, since it's not really on the foreground.
Related
I'm making a lock screen application on Android, I've gotten an event when the home button is pressed but I can't figure out how or what method to prevent the user from exiting the application via the Home button..
I use the method when the Home button is pressed then call the application back but this way there is a delay and still exits the application, maybe someone knows and can give me a little idea or technical for this case..
Thanks in advance..
here my button home event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:homekey
my recent app event in log
action:android.intent.action.CLOSE_SYSTEM_DIALOGS,reason:recentapps
You can't. The home button is a system button, there is no way to override the behavior of it. This is because any app that prevents you leaving it, other than a kiosk app, is pretty much malware by definition- you should never prevent the user from leaving your app. And if you're building a kiosk app, you'd be making it a launcher (I'd also highly recommend not using React Native for that, as the performance is low and a launcher needs to be lightweight to lead quickly.
Is there any programming tricks that makes your application unclosable?
For example: You touch the back or the home button, but they don't do anything.
Or at least is there a way that your application blocks some applications to open?
I don't think you can stop user from moving your application to background unless it's some kiosk mode app. And the method to do that is to become device administrator and override all possible callback methods - home, back, settings, notification area etc.
If you just want to prevent your app from getting closed due to user activity you can show a persistent notification. This will allow you app to run in background even if user presses home button.
Make a launcher/Home screen app:
When users click the home button, your app will show.
You control ALL apps that can be started
On devices running android lolipop, you can use the screen pinning option available in your ROM.
NOTE: This is ROM feature, you don't have to do anything in your app.
See this great article about it.
yes its to get set the on backpressed method to.
moveTaskToBack(true);
finish();
Are you trying to hack in android OS ? Let me tell you that android apps are sandboxed, which isolates your app data and code execution from other apps.
I am developing an app for android. It is not always clear to me when the app will be terminated by the OS. Sometimes it happens when you press the back button and sometimes when you press the home button. What is the logic behind this?
My app must be keep activated during a long period (when you run it the app must stay resident). Also another question is if it is possible to popup when an event comes in and activate the screen and bring it to the front.
Does somebody made this already? Or is there more information about this (how to do it). Search the internet but doesn't find some useful things.
Pressing the Back button on the main activity will finish and exit the app.
Pressing the Home button will pause and leave the app in the background, it will return to the previous state when it's restored.
Override the onBackPressed() method on the main activity if you don't want it to quit when the back button is pressed.
If you want an event to occur when the screen is shown, override the onResume() method and do the checks and event required in there.
Being that your answer is with Flex the issue is that you need to listen to the stage's keyDown event.
stage.addEventListener(KeyboardEvent.Key_DOWN, yourHandler);
Then you need to response to the back button and inhibit this - if your intent is to stop the back button.
private function _onStage_keyDownHandler(event:KeyboardEvent)
{
if(event.keyCode == Keyboard.BACK)
{
event.stopImmediatePropogation();
event.preventDefault();
//your code here
}
}
And one more moment - android can close your app when it thinks that it need more memory for more recent apps.
And you may need to use native extensions or even develop your app in java if you want to implement reliable resident behavior.
Update: java service+ air ui example:
http://www.jamesward.com/2011/05/11/extending-air-for-android/
end of update
And you must know that air apps eat at least 30mb of memory(if they are empty and do nothing), normally they will start from 50-70mb. I guess that no user will wish to allow another 70mb of his memory-hungry device to be eaten by something not critical.
And for automatic maximizing of your window you may need root access.
My requirement is to create Custom LockScreen, using below link http://code.google.com/p/contactowner/source/browse/#svn%2Ftrunk%2Fsrc%2Fcom%2Fappengine%2Fparanoid_android%2Flost i am able to create working Fine. But my Problem is when i press HOME button it is opening the Launcher screen. (1) How to Block home button in android ? (2)If it is not possible, How few custom lock screen .apks in the android market able to block Home button.
How can i achieve that ?
Appreciate your help...
You cannot intercept the key and do this unless you have access to the android source code and can change it. From an app's perspective, you can't do this unless you have the source either. Keep in mind that this is Frowned upon in android.
So the only thing you have available is onUserLeaveHint() which is a method from an Activity. But you still CANNOT stop a user from going home.
Ref:
http://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint()
Here is proof that you cannot do it directly
public static final int KEYCODE_HOME
Since: API Level 1
Key code constant: Home key. This key is handled by the
framework and is never delivered to applications.
Constant Value: 3 (0x00000003)
actually it is possible to block the home button , as locker replacement apps do (like this one and this one) . however , they do it using a sneaky way which might not work on some devices and/or future versions of android (hint: look at the code of android OS - where and when in the entire runtime of the OS is the home button being blocked from the user?) .
that's why the best thing to do in order to do it nicely is to capture the home button by acting as a launcher . then , when it's time to unlock the locker , you call the original launcher.
another advantage of using this method is that the locker will "stay better" in the memory and will be the first one that will be launched upon bootup (no need for special permission for bootup ) .
it's possible!
use window params setType(TYPE_SYSTEM_ERROR) and you'll get what you want.
JoxTraex is probably right , you shouldn't disable HOME key, or else users will report your app in future
But there is a way to detect home button press,
Check the answer to this question
The question I'm about to ask may seem dangerous for the user, so here's the story before the question:
I'm working in a compagny that tries to sell Galaxy Tabs to schools (children under 10). So, I've been asked to develop an application that starts on boot showing a login screen. The child HAS to log in before he's allowed to use the tablet (just like logging in a computer).
My application starts on boot, shows the login screen, all buttons are blocked (the kid must not be able to use the tablet before the application lets him) except the home button.
fortunately, it seems impossible to block the home button.
I've been trying to rebring the application to front when onpause/onstop is called, this kind of hacks.
So my question is : Can I prevent an user to quit my application until I let him do so?
I know this sounds like a virus, I'm not really happy to be looking for this kind of solution either.
You have to build a custom Home screen, and then set it as the default Home application.
EDIT: see more on this previously asked question (at How can I create a custom home-screen replacement application for Android?). You can just make your authorization the default Home application, then when they log in it forwards to the regular Home screen. If they hit the home button your app gets called, can check if they have logged in and if they have will just send them to the regular home screen.