【问题标题】:Android: How to enable device administraton?Android:如何启用设备管理员?
【发布时间】:2012-05-02 10:21:26
【问题描述】:

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

这是我的代码:

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

}

此代码没有显示任何内容。我该怎么办?

非常感谢...

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

【问题讨论】:

    标签: android admin device


    【解决方案1】:

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

    Window window = getWindow();
    WindowManager.LayoutParams windowParams = window.getAttributes();
    windowParams.screenBrightness = 0;
    window.setAttributes(windowParams);
    

    【讨论】:

    • 非常感谢您的回答,但这并不能回答我的问题,如果我使用此代码,我将无法再从待机状态退出。
    猜你喜欢
    • 2012-05-21
    • 2012-03-07
    • 1970-01-01
    • 2013-08-02
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 2014-03-07
    相关资源
    最近更新 更多