问题
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