我正在使用以下代码实现Kiosk模式,并在我第一次运行我的应用时将其设置为默认值
public class KioskActivity extends Activity {
final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(flags);
getActionBar().hide();
setContentView(wenchao.kiosk.R.layout.activity_lock_activity);
DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName mDPM = new ComponentName(this, MyAdmin.class);
if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {
String[] packages = {this.getPackageName()};
startLockTask();
} else {
Toast.makeText(getApplicationContext(),"Not owner", Toast.LENGTH_LONG).show();
}
setVolumMax();
Button lock_btn = (Button)findViewById(wenchao.kiosk.R.id.lock_button);
Button unlock_btn = (Button)findViewById(wenchao.kiosk.R.id.unlock_button);
Button appButton = (Button) findViewById(R.id.appButton);
lock_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
startLockTask();
return false;
}
});
unlock_btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
stopLockTask();
return false;
}
});
appButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
......
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_VOLUME_UP){
Toast.makeText(this, "Volume button is disabled", Toast.LENGTH_SHORT).show();
return true;
}
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN){
Toast.makeText(this, "Volume button is disabled", Toast.LENGTH_SHORT).show();
return true;
}
return super.onKeyDown(keyCode, event);
}
private void setVolumMax(){
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamVolume(
AudioManager.STREAM_SYSTEM,
am.getStreamMaxVolume(AudioManager.STREAM_SYSTEM),
0);
}
}
它看起来对我很完美,我以为我达到了我想要的效果。
这是痛点,当我从顶部向下滑动,获得带控件的透明栏时,我没有假设:
实际上它会持续几秒然后消失(但我不希望它出现在我的应用程序中,即使是毫秒)
当我转移到其他应用程序时,使用点击应用程序按钮,然后回到我的应用程序,得到它,它很烦人:
每当它出现时永远不会消失,除了关闭应用程序之外别无选择,以摆脱
值> styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
values-v21&gt; styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
</style>
</resources>