简体   繁体   中英

Disabling home button Android

I have read a lot about how we cannot override or disable home button. And I too agree that its risky in many ways as some people might take wrong advantage of it. But unfortunately its a requirement in my app.

I was able to hide them in my device which runs on Android Kitkat using the Immersive feature. Its true that when user swipes from the edge of the screen it makes the status and navigation bar visible. But I found out a way to disappear it again by calling Immersive every second or so using CountDownTimer . The result was satisfactory and got the job done.

But I do not have any solution for Android devices which does not run on Kitkat as the bars appear every time we interact with screen. Even though the bars hide but appearing every time the user touches the screen does not look good. So Immersive feature is out of question since it does not run except for Kitkat.

I did try out another solution suggested in various SO posts -

Making my activity visible when the screen is locked. This helped me to get rid of the third button (button right side of Home button, not sure what it is called). And we could easily handle back button. But still home button is remaining. I need to somehow make this Home button disable or do nothing. Or atleast (worst case scenario) navigate to my app when ever I click on home button (Is it possible?)

What I am looking for is the user should only be able to leave the app from a button which I have provided in my app, there should'nt be any other way. Can someone suggest me a way to achieve this?

I am on a deadline here. Any help on this will be helpful to me greately. I am also open for other ways of achieving the above nonesense feature.

Thanks :)

Android 5.0 introduces a new screen pinning API that lets you temporarily restrict users from leaving your task or being interrupted by notifications. Once your app activates screen pinning, users cannot see notifications, access other apps, or return to the home screen, until your app exits the mode.

https://developer.android.com/about/versions/android-5.0.html

I was interested on this subject, and a topic discussing the same was release weeks ago. the conclusion is on older versions exists external librarys and/or simple code to implement and override home button.

On +4.0 i dont think so. check this topics: Disable Home button in Android 4.0+ and https://stackoverflow.com/a/10025904/3640637

hope it helps.

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />

Add this to your activity in the manifest.

I think would be better for you to change your approach. If you want to make something which never will be closed by Home button, just make service and add a view to the Window Manager. With the Layout params you will be able to draw on top of everything that even home button won't close it. Life sample could be Facebook messengers new chat. You can make 2 services. One to cover status bar layer and another one to cover the other part of the screen. Please have a look at this samples

I have tried to block Home button with the sample below, but this blocks only HARD home button - https://github.com/shaobin0604/Android-HomeKey-Locker

Your explanation helps only for the newer versions. So just combine or take the first one to achieve that. Good Luck :)

If people here have some other good approach, then I would like to hear that, because it is interesting for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM