2

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?

prmottajr
  • 1,816
  • 1
  • 13
  • 22
Bob
  • 21
  • 2
  • Have you tried retrieving KeyCode for the Home button? – Muhammad Maqsoodur Rehman Feb 14 '14 at 08:06
  • I need to capture pressed event even app is in background. KeyCode should be working in Activity,but not enough for me – Bob Feb 14 '14 at 08:22
  • I think u need to use service that responds to hard key press events by registering a BroadcastReceiver. http://stackoverflow.com/questions/12792606/android-listener-for-hard-keys-press-at-background – Neha Feb 14 '14 at 08:50
  • I registered a BroadcastReceiver indeed. The diffirent is I want to capture home key not media key.As i said,my code is working when screen is not locked.My problem is that code is not working when screen is locked – Bob Feb 14 '14 at 09:06

0 Answers0