0

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 :)

ik024
  • 3,566
  • 7
  • 38
  • 61

4 Answers4

2

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

Zsolt Safrany
  • 13,290
  • 6
  • 50
  • 62
1

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.

Community
  • 1
  • 1
PedroHawk
  • 622
  • 5
  • 19
  • Thanks I am looking into making my app as Home screen. but is it possible to disable my app as home screen from within the code. Since eventually I will have to navigate to android's default home screen. – ik024 Jul 08 '14 at 09:00
0
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.HOME" />

Add this to your activity in the manifest.

EatHeat
  • 80
  • 8
  • What would this do? I think I saw this in many other post where ppl say it doesnot work. Btw what does it do ? – ik024 Jul 08 '14 at 08:35
  • It returns you to the activity that has this intent on pressing your home button. This is what custom launchers use. – EatHeat Jul 08 '14 at 08:38
  • okay so far so good. but is it possible to disable my app as home screen from within the code. Since eventually I will have to navigate to android default home screen. – ik024 Jul 08 '14 at 08:59
  • Let the user select a launcher except yours. Detect if the user is in your app or not. If yes, then do nothing. If no, then redirect him to the launcher he chose before. – EatHeat Jul 08 '14 at 09:22
0

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.

Community
  • 1
  • 1
X-HuMan
  • 1,488
  • 1
  • 17
  • 37