App discovery is deleted from the phone / device administrator

There are some applications that can detect when they are removed from Phone / Device Administrator. I searched on the Android developer website and could not find a flag or receiver that starts when a user clicks on this flag next to our application in the “Phone / Device Administrator”.

+4
source share
2 answers

The broadcast receiver has a callback function that extends from the class DeviceAdminReceiver, which is as follows. When the user presses the deactivation button, this function is called onDisableRequestedright before the application is disconnected from the device administrator, after the user presses the deactivate button, it calls onDisabled. First of all, we need to call the launchpad (home screen), and then lock the device. The user will not be able to deactivate if we use this logic. If there is a more optimized way, feel free to share / update.

@Override
    public CharSequence onDisableRequested(Context context, Intent intent) { 
            Intent homeScreenIntent = new Intent(Intent.ACTION_MAIN);
            homeScreenIntent.addCategory(Intent.CATEGORY_HOME);
            homeScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(homeScreenIntent);
            DevicePolicyManager deviceManger;
            deviceManger = (DevicePolicyManager) context.getSystemService(
                    Context.DEVICE_POLICY_SERVICE);
            deviceManger.lockNow();
         return context.getString("App won't work if you disable this setting");
    }
0
source

ACTION_DEVICE_ADMIN_DISABLED, , onDisabled (, ). - API- DevicePolicyManager onDisabled, , .

0

Source: https://habr.com/ru/post/1684687/


All Articles