Device administrator disabling

≡放荡痞女 提交于 2020-01-02 11:47:48

问题


Device administration app can not be uninstalled if it is not disabled. User can disable "Device Administrators" from the settings. When company gives android devices to its employees, company wants to have a control over devices, their statuses and policies, but user can easily get rid of that control. Does anybody know how it is possible to prevent user from disabling Device Administrators? Thanks.


回答1:


There's no way to prevent the user from disabling Device Administrators, at least using the published APIs. The best you can do is disallow programs from running if certain policies aren't in place.

Some manufacturers (e.g., Samsung) have extended the base APIs to allow additional capabilities, but these are not part of the standard Android platform.




回答2:


In DeviceAdminReceiver.java you could do something like this onDisableRequested:

public CharSequence onDisableRequested(Context context, Intent intent) {

    SharedPreferences settings = context.getSharedPreferences(MainActivity.class.getName(), 0);
    String DEVICE_ADMIN_CAN_DEACTIVATE = settings.getString("DEVICE_ADMIN_CAN_DEACTIVATE", null);
    if(DEVICE_ADMIN_CAN_DEACTIVATE.equals("ON")){
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(startMain);
        return "OOPS!";
    }else{
        String msg_char_onDisable = context.getResources().getString(R.string.msg_char_onDisable);
        return msg_char_onDisable;
    }
}


来源:https://stackoverflow.com/questions/6457690/device-administrator-disabling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!