我正在开发一个作为Admin
. 我可以使用以下代码来做到这一点
DemoDeviceAdminReceiver.jav:
public class DemoDeviceAdminReceiver extends DeviceAdminReceiver {
static final String TAG = "DemoDeviceAdminReceiver";
/** Called when this application is approved to be a device administrator. */
@Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
Toast.makeText(context, R.string.device_admin_enabled, Toast.LENGTH_LONG).show();
Log.d(TAG, "onEnabled");
}
/** Called when disabling device administrator power. */
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
Toast.makeText(context, R.string.device_admin_requesting_disable, Toast.LENGTH_LONG).show();
Log.d(TAG, "onDisableRequested");
return super.onDisableRequested(context, intent);
}
/** Called when this application is no longer the device administrator. */
@Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
Toast.makeText(context, R.string.device_admin_disabled, Toast.LENGTH_LONG).show();
Log.d(TAG, "onDisabled");
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
super.onPasswordChanged(context, intent);
Log.d(TAG, "onPasswordChanged");
}
@Override
public void onPasswordFailed(Context context, Intent intent) {
super.onPasswordFailed(context, intent);
Log.d(TAG, "onPasswordFailed");
}
@Override
public void onPasswordSucceeded(Context context, Intent intent) {
super.onPasswordSucceeded(context, intent);
Log.d(TAG, "onPasswordSucceeded");
}
}
清单:
<receiver
android:name=".DemoDeviceAdminReceiver"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
</receiver>
res/xml/device_admin_sample.xml:
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock />
<wipe-data />
<expire-password />
<encrypted-storage />
</uses-policies>
</device-admin>
一切正常,但我不知道每当用户点击disable the app
from时如何要求输入密码admin rights
。
请帮助解决这个大谜题。谢谢