I want to intercept home button click of Android device in lollipop version.
Asked
Active
Viewed 1,020 times
2 Answers
1
I think this can be done in another style if suits your requirement. By
creating your activity as home activity. If you want to disable home button
and show your custom application activity as launcher when home button is
pressed. Just add these lines in manifest for that activity for which you want your launcher.
<activity
android:name="com.example.TempActivity"
android:clearTaskOnLaunch="true"
android:excludeFromRecents="true"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:stateNotNeeded="true" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
if user presses the home button, Android will ask for which launcher you want your home. Then your have to select your application launcher ALWAYS not ONLY ONCE.
if you want fully disable the user, so that he cant move to another screen then set theme to fullscreen with NoTilebar.
-
i'm also facing same problem but onAttachedToWindow() method cant be override. it show error.....please check it. – Garg Sep 08 '15 at 06:07
-
sorry mayuri i have already try this code but not work for me you can visit my problem ..... if you have any soloution and you want , i can mail my code to you. please see this link http://stackoverflow.com/questions/29920762/how-to-override-the-home-key-function – Garg Sep 08 '15 at 06:26
-
what is exactly problem...for disable home button it ll work..show your stacktrace or any bug? – Mayuri Sep 08 '15 at 06:31
-
i want develop a screen lock app like pattern lock. so i want disable home key until unlock screen. – Garg Sep 08 '15 at 06:57
0
Use this method:
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
};

Vadim Kotov
- 8,084
- 8
- 48
- 62