Android 如何知道我的应用程序是否为管理员
我正在创建一个应用程序,它将Android 如何知道我的应用程序是否为管理员,android,android-layout,service,broadcastreceiver,admin,Android,Android Layout,Service,Broadcastreceiver,Admin,我正在创建一个应用程序,它将我的设备作为管理员工作很棒 但是我想在我的应用程序从设备卸载时触发一些消息。 当用户从管理员中删除时 如何知道是否选中了我的应用程序设备管理员? 我正在使用android内置的管理应用程序演示 请告诉我一些想法。您必须扩展DeviceAdminReceiver并 public class DeviceAdmin extends DeviceAdminReceiver { @Override public void onEnabled(Context
我的设备作为管理员
工作很棒
但是我想在我的应用程序从设备卸载时触发一些消息。
从管理员中删除时
应用程序设备管理员?
请告诉我一些想法。您必须扩展DeviceAdminReceiver并
public class DeviceAdmin extends DeviceAdminReceiver {
@Override
public void onEnabled(Context context, Intent intent) {
Log.i(this, "admin_receiver_status_enabled");
// admin rights
App.getPreferences().edit().putBoolean(App.ADMIN_ENABLED, true).commit(); //App.getPreferences() returns the sharedPreferences
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "admin_receiver_status_disable_warning";
}
@Override
public void onDisabled(Context context, Intent intent) {
Log.info(this, "admin_receiver_status_disabled");
// admin rights removed
App.getPreferences().edit().putBoolean(App.ADMIN_ENABLED, false).commit(); //App.getPreferences() returns the sharedPreferences
}
}
应用程序中的任意位置:
DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName mAdminName = new ComponentName(this, DeviceAdmin.class);
if(mDPM != null &&mDPM.isAdminActive(mAdminName)) {
// admin active
}
我使用的是这种方式。但当如何在后台知道我的应用程序管理员是禁用的。onDisabled将被调用,即使你的应用程序在后台或根本没有运行。您可以将状态保存在SharedReferenceshey@malimo how to know my device admin(当我的应用程序未处于运行状态时如何了解我的设备管理员)。很抱歉,我不理解您的问题。是否要检查您的应用程序是否为其他应用程序中的设备管理员?否,如果我的应用程序位于后台,并且用户在我希望的时候卸载该应用程序,请将一个对话框显示为消息。如果按“确定”,则“管理员”为“禁用其他”。