Skip to content

Instantly share code, notes, and snippets.

@5ZSQ
Last active September 13, 2017 02:26
Show Gist options
  • Save 5ZSQ/450f9b1d12adfd6f253a5edc3b3b5f6f to your computer and use it in GitHub Desktop.
Save 5ZSQ/450f9b1d12adfd6f253a5edc3b3b5f6f to your computer and use it in GitHub Desktop.
Android - Home键广播监听
private static class HomeBtnBroadcastReceiver1 extends BroadcastReceiver {
private String action;
final String SYSTEM_HOME_KEY;
final String SYSTEM_RECENT_APPS;
private HomeBtnBroadcastReceiver1() {
this.action = null;
this.SYSTEM_HOME_KEY = "homekey";
this.SYSTEM_RECENT_APPS = "recentapps";
}
public void onReceive(Context context, Intent intent) {
this.action = intent.getAction();
String dlg = "android.intent.action.CLOSE_SYSTEM_DIALOGS";
boolean isequal = dlg.equals(this.action);
if(isequal && TrackingIO.isAppOnForeground()) {
String reason = intent.getStringExtra("reason");
if(reason != null) {
if(reason.equals("homekey")) {
CommonUtil.printLog("TrackingIO", "=========== pressed home button ===========");
TrackingIO.stopHeartBeat();
} else if(reason.equals("recentapps")) {
CommonUtil.printLog("TrackingIO", "=========== long pressed home button ===========");
}
}
}
}
}
@5ZSQ
Copy link
Author

5ZSQ commented Sep 13, 2017

监听Home键

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment