Last active
September 13, 2017 02:26
-
-
Save 5ZSQ/450f9b1d12adfd6f253a5edc3b3b5f6f to your computer and use it in GitHub Desktop.
Android - Home键广播监听
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ==========="); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
监听Home键