Android - Is It possible to disable the click of home button
I'm pretty sure Toddler Lock just uses a BroadcastReciever and listens for Intent.ACTION_MAIN
and the category Intent.CATEGORY_HOME
- that's why when you first launch it, it tells you to check the "use this application as default" box, and makes you select toddler lock.
So, it's not really blocking the Home button at all, it's just setting itself up as the default broadcast receiver for:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
When you launch Toddler Lock, it probably sets an internal flag, and if you press the home button, it just brings the window to the front. If the flag is not set, it probably launches Launcher explicitly.
I hope that makes sense. It's just a theory, but I'm almost 100% sure that's how it's done.
Add following code to your activity:
@override
public void onAttachedToWindow()
{
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
Edit:
This works in all older version of android. But will not work in ICS
and jelly bean and will give you crash in app
What does this 4 line java code means in android application?
Add this in your manifest.xml for your main activity:
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
The HOME button will always (re-)launch your activity. Works in Froyo.