I need to lock the device for one application only.
I use a line in my project that requires my app to make a launcher
. So, the initial screen of the device is my application, and HomeButton
always points to the application. Line below.
[IntentFilter(new[] { Intent.ActionMain }, Categories = new[] { Intent.CategoryHome, Intent.CategoryDefault })]
I was able to lock the buttons to prevent the user from accessing the device settings by changing the *.kl
files inside the / system / usr / keylayout folder. But the only way to do this is with the rooted device. I'm looking for ways to not need to rotate the device.
The BackButton
, I can "lock" on the device within my application, using public override void OnBackPressed()
.
The volume buttons I can "lock" on the device using the code below.
public override bool OnKeyDown(Android.Views.Keycode keyCode, KeyEvent e)
{
switch (keyCode)
{
case Android.Views.Keycode.VolumeUp:
Toast.MakeText(this, "Volume Up pressed", ToastLength.Long).Show();
e.Dispose();
return true;
case Android.Views.Keycode.VolumeDown:
Toast.MakeText(this, "Volume Down pressed", ToastLength.Long).Show();
e.Dispose();
OnUserLeaveHint();
return true;
}
return base.OnKeyDown(keyCode, e);
}
However, the only button I can not block is AppSwitch
, which is the easiest way to access the settings.
I tried the code below, but without success.
protected override void OnPause()
{
base.OnPause();
ActivityManager activityManager = (ActivityManager)GetSystemService(Activity.ActivityService);
activityManager.MoveTaskToFront(TaskId, 0);
}
The taskbar I do the lock also. But only within the application.
I also read about AccessibilityService
, where we can change creating a Hook on the buttons pressed. But I did not get much information and the tests I did were unsuccessful.
Any ideas how to block?
I continue with the attempts. This is unfortunately a trial and error. I accessed the Android Management API and set up a business, created a policy, and was able to import it into the device. However, there is no way to lock the device settings (because it is one of the ways to restore the default settings), which is one of the items needed for my application.
I did not want to appeal to .kl files that only work with the rooted device. Anyone have any ideas?