# Disable Home Key

### Disabling Home Key in APK

* Overview: This section explains how to disable the home key within an Android application (APK).
* Demo Availability: Access a practical demonstration by downloading the provided [demo](https://github.com/SmartPOSSamples/DisableStatusBarOrHomeBtnInApp).
* Setting Permissions: Define specific permissions in your application to capture home or back key events.
* Capturing Key Events: Implement functionality to detect when the home or back key is pressed within the application.

#### Permission

```xml
 android.permission.CLOUDPOS_DISABLE_HOME_KEY
```

The application declares permissions in the manifest.

### Disabling Home Key in Activity

* Overview: This part focuses on disabling the home key specifically in an Android activity.
* Demo Availability: A demo for this functionality is available for download [demo](https://github.com/SmartPOSSamples/DisableStatusBarOrHomeBtnInActivityInW1).
* Defining Permissions and Window Type:
  * Set necessary permissions in your activity.
  * Change the window type of the activity to either 'TYPE\_KEYGUARD' or 'TYPE\_KEYGUARD\_DIALOG'.
* Event Capture: With these settings, the application will be able to capture events when the home or back key is pressed.

#### Permission

```java
 android.permission.CLOUDPOS_DISABLE_HOME_KEY_IN_ACTIVITY
```

The application declares permissions in the manifest.

The code snippet is as follows:

{% code overflow="wrap" lineNumbers="true" %}

```java
public void onAttachedToWindow() {                                      
	super.onAttachedToWindow();                                           
	try {                                                                 
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); 
	} catch (Throwable e) {                                               
		e.printStackTrace();                                                
	}                                                                     
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://smartpossdk.gitbook.io/cloudpossdk/faq/other-development/disable-home-key.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
