0

我想通过我的应用程序关闭屏幕,但我无法获得设备管理员。

这是我的代码:

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);
}

}

这段代码没有告诉我任何东西。我该怎么办?

非常感谢...

请不要向我显示任何没有解决方案的链接...

4

1 回答 1

0

作为一种解决方法,您可以根据亮度级别的变化尝试这个技巧。

Window window = getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.screenBrightness = 0;
window.setAttributes(windowParams);
于 2012-05-02T10:28:13.683 回答