How to detect hardware home key pressed in service android?

389 views Asked by At

Basically I am trying to find my home key pressed event in my Service,

I used broadcast receiver with intent-filter "CLOSE_SYSTEM_DIALOGS" & I reached half a way... Now it works perfect with soft home key but not if device has hardware home key (example : in Samsung J7 I cant receive broadcast).

Anyone have any idea to solve this problem?

1

There are 1 answers

0
Muhammad Shan On
public class MainActivity extends Activity {
  boolean homePressed = false;


@Override
public void onBackPressed() {
    homePressed = false; 
}

@Overide
public void onResume() {
    super.onResume();
    homePressed = true;
}

@Override
public void onPause() {
    super.onPause();
    if(homePressed) { Log.i(TAG, "Got it"); }
}

try this one .