How to prevent the app from being "minimized" by AppSwitch (RecentApps) Xamarin Android

8

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?

    
asked by anonymous 22.03.2018 / 15:57

1 answer

3

After much research and conversation with other colleagues, we found that in the OnPause() method, you can lock the AppSwitch(RecentApps) button using the code below.

    protected override void OnPause()
    {
        base.OnPause();

        ActivityManager activityManager = (ActivityManager.FromContext(this));
        activityManager.MoveTaskToFront(TaskId, 0);
    }

Some bugs may occur if pressed many times followed, such as black flashing screen, but only when pressed many times in a row.

    
24.04.2018 / 14:51