0

I disabled the notification bar using the following code

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

I used the following code to disable the home button

@Override
public void onAttachedToWindow()
{  
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);     
    super.onAttachedToWindow();  
}

but when I use the above code to disable the home button, the notification shows up on top.
Can anybody tell me how to achieve both of these?

jaisonDavis
  • 1,407
  • 2
  • 22
  • 36
  • 1
    Why would anyone want to disable the home button? – Egor Jul 06 '12 at 08:13
  • I am making a lockscreen – jaisonDavis Jul 06 '12 at 08:17
  • I agree with Egor. The home button is there for a good reason, and should not be disabled. I doubt Android even let you for this exact reason. EDIT: Ok, i can see why in the case of a lockscreen. – IAmGroot Jul 06 '12 at 08:17
  • 2
    The code you use to disable the home button doesn't work on API level 14+. – Benito Bertoli Jul 06 '12 at 08:34
  • check this out...http://stackoverflow.com/a/2650010/1395342 – jaisonDavis Jul 06 '12 at 08:40
  • how do I implement the comment in the above link? – jaisonDavis Jul 06 '12 at 08:41
  • 1
    "I am making a lockscreen" -- you are making an app that claims to be a lockscreen, but in reality reduces the user's security. The only way to really implement a "lockscreen" is as part of the operating system. All third-party lockscreens can be trivially defeated by rebooting in safe mode. And, since these third-party lockscreens ask the user to disable the OS's own lock screen security, you wind up with a less-secure device overall. – CommonsWare Jul 06 '12 at 12:30
  • 1
    The users can see the security permissions and they know what they are getting into and a lockscreen is technically any app that locks a phone.I am not planning to offer pattern or password unlock – jaisonDavis Jul 06 '12 at 12:41

3 Answers3

1

Add this code in your onCreate() method before calling setContentView()

this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Chilledrat
  • 2,593
  • 3
  • 28
  • 38
0

You could intercept the HOME button via onKeyDown callback, and take appropriate action, but I'm not sure if it will work. Didn't tried myself.

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            // Do nothing, or everything else you want to do when the HOME is pressed.
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

use

<activity
    android:label="@string/app_name"
    android:name=".MyActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />

instead

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
Xiao
  • 33
  • 3