android home键重写,屏蔽,模拟
来源:互联网 发布:阿里妈妈淘宝客 编辑:程序博客网 时间:2024/06/07 12:48
1.屏蔽home键的两种方法:
(1) 在以前版本中重写
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);super.onAttachedToWindow();
}
(2) 4.0以上版本:在setContentView(R.layout.activity_main)前添加this.getWindow().setFlags(0x80000000, 0x80000000)就可以(但部分机型会出现屏 幕黑屏或者其他问题)。
然而上面的两种方法并不能百分之百的屏蔽home键,有些手机会被屏蔽例如华为p8,而oppo却没被屏蔽(到现在我并没有找到彻底屏蔽的办法)。
2.重写监听home键的两种方法:
(1)屏蔽home键(采用上面的方法)+重写onkeydown
(2)广播
class HomeKeyEventBroadCastReceiver extends BroadcastReceiver {
static final String SYSTEM_REASON = "reason";
static final String SYSTEM_HOME_KEY = "homekey";// home key
static final String SYSTEM_RECENT_APPS = "recentapps";// long home key
@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处理点
Log.e("homekey", "home键被点击");
Toast.makeText(BaseActivity.this, "Home键被点击", Toast.LENGTH_SHORT).show();
} else if (reason.equals(SYSTEM_RECENT_APPS)) {
// long homekey处理点
Log.e("homekey", "长按home键");
Toast.makeText(BaseActivity.this, "Home键长按", Toast.LENGTH_SHORT).show();
}
}
}
}
}
注册广播:
HomeKeyEventBroadCastReceiver receiver = new HomeKeyEventBroadCastReceiver();
registerReceiver(receiver, new IntentFilter(
Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
3.模拟home键:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
- android home键重写,屏蔽,模拟
- android 4.0如何屏蔽和重写home键
- Android HOME键屏蔽
- Android 屏蔽HOME键
- Android屏蔽home键
- android屏蔽home键
- Android屏蔽home键
- Android 屏蔽Home键
- android 屏蔽home键
- android 屏蔽home键
- Android屏蔽HOME键
- android屏蔽Home键
- android 屏蔽HOME键
- android home键屏蔽
- Android 屏蔽Home键
- Android 屏蔽home键
- Android中屏蔽返回键,HOME键以及模拟HOME键返回效果的方法
- 屏蔽 Home 键 (Android|)
- android中static修饰的变量在Activity销毁后,还存在吗
- tq2440开发板使用过程中遇到的问题
- java设计模式--适配器模式
- SQL SELECT DISTINCT 语句
- solr权重
- android home键重写,屏蔽,模拟
- 通信(Socket)
- oc错误:control reaches end of non-void function
- HTML5+Canvas 正方体旋转
- Raspberry Pi 图片网络化--curl 上传文件至Aliyun的ftp服务器
- 浅谈iOS中MVVM的架构设计与团队协作
- 个人疑问,待解决
- 各国开源软件和商业软件
- Ruby运算符重载