屏蔽安卓系统Home键

Settings.System.putInt(getContentResolver(),"sys.home_key_to_app", 1);
Settings.System.putInt(getContentResolver(),"sys.home_key_to_app", 0);

     写字符串Settings.System.putString(ContentResolver resolver, String name, String value)

     读字符串Settings.System.getString(ContentResolver resolver, String name)

 

     写整型Settings.System.putInt(ContentResolver resolver, String name, int value)

     读整型Settings.System.getInt(ContentResolver resolver, String name,0)

说明:以上的值为为非1时代表,不屏蔽home键,为1时代表屏蔽home键;这种操作是修改安卓系统设置的数据库,需要申请权限的,在清单文件中声明:    
android:name="android.permission.WRITE_SETTINGS" />
android:name="android.permission.READ_SYNC_SETTINGS"/>
如果是6.0以上的手机需要:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// 判断是否有WRITE_SETTINGS权限
if(!Settings.System.canWrite(this)) {
// 申请WRITE_SETTINGS权限
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName())); startActivityForResult(intent, REQUEST_CODE);
} else {
dosomething(); }
}
else { dosomething();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intentdata) {
if (requestCode == REQUEST_CODE) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 判断是否有WRITE_SETTINGS权限
if (Settings.System.canWrite(this)) {
dosomething();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
注:这样申请权限好像不起作用,它需要用户手动去开启权限
private String[] permissions = new String[]{
 Manifest.permission.WRITE_SETTINGS,
Manifest.permission.READ_SYNC_SETTINGS
};

你可能感兴趣的:(Android)