Disable Home Key - android

i am trying to create a lock screen and for that i need to disable the home button..
i found the following code, its recommended by many and I tried it:
#Override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}
Now i know what its doing, I tried it on HTC Explorer, Sony Ericsson Experia Neo V, and Samsung Galaxy S2..
The code works in HTC and Sony but it seems to have no effect on Samsung Galaxy s2..
Please note that Samsung is rooted while others not...is rooted device the problem??
Any Suggestions pls?

I believe the problem is that the Home key really isn't meant to be disabled.

The only way to overwrite the home button in android is to act as a home replacement, so your app is opened when home is pressed. The user has to set your app as default app and when the screen is unlocked you open the default launcher.
The lockscreen in android isn't meant to be replaced.

Related

Android Studio: Is it possible to trigger hardware menu button

I have an android application which kind of like a home screen of the build-in screen on android phone. I can list all the available applications and run them. One thing I don't know how to do is when user run an application from my apps, my application can trigger the hardware menu button to show the current application menus.
Is this possible ? If not, what about doing it if the device was rooted.
In activity use override onKeyDown like this :
#Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode) {
case KeyEvent.KEYCODE_MENU:
doSomething();
return true;
}
return super.onKeyDown(keycode, e);
}
In order to open up the menu from other application apart from the caller application, the device have to be rooted before the code to work.

Samsung Galaxy XCover/Active button

the Galaxy S4/S5/S6 Active and the Galaxy XCover models have this extra hardware button. In the settings the user can choose which app the button should open when it is pressed.
I'm developing an app that is specifically targeted at the Galaxy XCover 3. When the user opens the app for the first time, I want to ask the user if they want to let the hardware button open my app.
I have tried to register a broadcastreceiver on the "Camera button" event, but this doesn't work.
Does anyone know how I could achieve this result?
I had the same problem and found a solution.
Use the code below to find the keycode.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
System.out.println("keycode -->" +keyCode);
System.out.println("Key event -->" + event );
return false;
}
Then make a final int with the keycode.
final int ACTIVE_BUTTON = 1015;
And last write your onKeyDown event.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event){
switch(keyCode){
case ACTIVE_BUTTON:
//your action here
return true;
}
}
from Samsung:
Hardware key re-mapping
Refer to this section to integrate a hardware key re-mapping configuration using the Samsung Knox SDK.
PTT key re-mapping considerations
If a PTT app vendor decides to use an intent defined by Samsung, an IT Admin can either leave the intent pre-populated, or enter an intent as provided by their PTT app vendor.
List a generic intent to a PTT vendor app
Vendors can also use the following intents for PTT key press and release actions:
For key press -> com.samsung.android.knox.intent.action.PTT_PRESS
For key release -> com.samsung.android.knox.intent.action.PTT_RELEASE
The following optional timestamp can also be considered:
Extra -> com.samsung.android.knox.intent.extra.EVENT_TIMESTAMP (with type long which will hold the Epoch timestamp of the event)
Secure PTT intents
The Samsung Knox team recommends registering an intent in manifest statically so KSP can wake the app if in a stopped state. Consider the following:
<receiver
android:name=".PTTKeyReceiver"
android:permission="com.samsung.android.knox.permission.KNOX_CUSTOM_SETTING"
android:exported="true" >
Optional Security: To ensure a PTT vendor app is listening to intent actions only from KSP, an app can add the above permission in the receiver, which is platform signature protected.
reference:
https://docs.samsungknox.com/admin/knox-service-plugin/Hardware_key_re-mapping.htm

How to handle device home button click efficiently?

I want to handle device home button click in my android application.When googled it is said that this
Link works.But I have some doubts.
Is it supported by all android versions?If not which of them are supported?
Is there any consequence exist because of using onAttachedToWindow() method?
Is there any way to handle Home button click(Except this)?
Thanks in Advance
This only works in previous version. But from os version 4.0 it is not working (although in my emulators this doesnt work after api level 11 but I am pointing ics according to many other links).
Found this on other posts.
On older Android version this is working. But Android changed this, because they say "Home Button should stay Home Button" and they don't want that anybody override the Home Button. And because of this reason your code is not working anymore.
If you want to do something when the home button is pressed, then do this in the onPause method.
yeah its work please try this code
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}
And now handle the key event like this,
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME)
{
Log.i("Home Button","Clicked");
}
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
}
return false;
};

How to override the side volume keys outside my android application

I would like to disable the side volume buttons so the only way to control the volume will be from a dedicated activity inside my android app.
I managed to disable it for all my activities by adding the following code:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d(TAG, "onKeyDown = " + keyCode);
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
return true;
}
return super.onKeyDown(keyCode, event);
}
But I don't know how to disable it for the activities i start from my app (for example I start the gallery app)!
I know it is possible as 'Volume Locker' app doing similar stuff.
It is not possible within public APIs to suppress the key events outside of your own Activities, if there is an app that has managed to do it what they are doing would be considered malicious by the platform designers and will get fixed at some point.
Based on the description given for that app (note: I've never used it personally)
Prevent accidental changes to your volume settings, install Volume Locker today.
This app helps prevent against accidental volume changes by confirming the change you made, by either tray notification or a pop up. If you don't approve the change, the volume will be reset within a set amount of seconds... By setting the timeout to "instant", the locked volumes will revert instantly without prompting.
I suspect what that is actually doing is listening for the volume buttons using a similar technique to the one in this answer and just reverting whatever change was made instantly(ish). That would make it seem to the user like the key press did nothing but in reality what happened is the volume changed and then quickly changed back.

my android app don't close itself

When I test my android application on my phone, the application don't want to quit and make a bug on my phone. My little app take 70MB on my phone and still alive all the day...
How can I close it?
Do I have to put a Listner for the button "return" or there is some methods made from the SDK???
Thanks !
EDIT:
My application still runing, even if I press "HOME" ... this is not normal, is it?
Application on mobile aren't meant to quit, because it's against the UX of mobile user.
Have a look at this discussion. Android: Is quitting an application frowned upon?
you can override onKeyDown function like this
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
finish();
}
return super.onKeyDown(keyCode, event);
}

Categories

Resources