I wrote a BroadcastReceiver
with ACTION_CLOSE_SYSTEM_DIALOGS
to capture the home button press event
:
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
{
String reason = intent.getStringExtra(SYSTEM_REASON);
if (reason != null)
{
if (reason.equals(SYSTEM_HOME_KEY))
{
//home key pressed
} else if (reason.equals(SYSTEM_RECENT_APPS))
{
// long pressed home key
}
}
}
}
This code only works when the screen is not locked. Any idea why this would not work with a locked screen? And how resovle it?