我想通过我的应用程序关闭屏幕,但我无法获得设备管理员。
这是我的代码:
DevicePolicyManager mDPM;
ComponentName mDeviceAdminSample;
private static final int REQUEST_CODE_ENABLE_ADMIN = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext=this;
mDeviceAdminSample = new ComponentName(this, Act_01_LockScreen.class);
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
}
@Override
public void onResume() {
super.onResume();
Boolean mAdminActive = isActiveAdmin();
if (!mAdminActive) {
// Launch the activity to have the user enable our admin.
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
mContext.getResources().getString(R.string.app_name));
startActivityForResult(intent, REQUEST_CODE_ENABLE_ADMIN);
// return false - don't update checkbox until we're really active
}else{
mDPM.lockNow();
}
}
private boolean isActiveAdmin() {
return mDPM.isAdminActive(mDeviceAdminSample);
}
}
这段代码没有告诉我任何东西。我该怎么办?
非常感谢...
请不要向我显示任何没有解决方案的链接...