监听home键的广播
public class HomeKeyReceiver extends BroadcastReceiver implements SanbotConstants{ private HomeKeyListener listener; public HomeKeyReceiver(){ } public HomeKeyReceiver(HomeKeyListener listener) { this.listener = listener; } // private static final String SYSTEM_DIALOG_REASON_KEY = "reason"; // //action内的某些reason // private static final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";//home键旁边的最近程序列表键 // private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";//按下home键 // private static final String SYSTEM_DIALOG_REASON_LOCK = "lock";//锁屏键 // private static final String SYSTEM_DIALOG_REASON_ASSIST = "assist";//某些三星手机的程序列表键 @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); //Lig.d("action = = > "+action); // if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {//Action // // String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); // if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) { // 短按Home键 // //可以在这里实现关闭程序操作。。。 // Lig.d("点击了Home键 . . . "); // if (listener != null) { // listener.onHomeKey(); // } // } else if (SYSTEM_DIALOG_REASON_RECENT_APPS.equals(reason)) {//Home键旁边的显示最近的程序的按钮 // // 长按Home键 或者 activity切换键 // // } else if (SYSTEM_DIALOG_REASON_LOCK.equals(reason)) { // 锁屏,似乎是没有反应,监听Intent.ACTION_SCREEN_OFF这个Action才有用 // // } else if (SYSTEM_DIALOG_REASON_ASSIST.equals(reason)) { // samsung 长按Home键 // // } // // } // if(action.equalsIgnoreCase(ACTION_TO_SCREEN)){ Lig.d("返回主屏按钮.被点击");if(listener!= null)listener.onHomeKey(); } } }