单击按钮时,我必须锁定模拟器。我使用此代码-
我不明白什么是活动和安全我的管理员
我使用此链接>以编程方式锁定安卓设备
public class adminActivity extends DeviceAdminReceiver
{
public static class Test extends Activity
{
Button btn;
DevicePolicyManager mDPM;
ComponentName mDeviceAdminSample;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(Test.this,
adminActivity.class);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, securemeAdmin);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (active)
{
mDPM.lockNow();
}
}
});
}
}
}
我也使用键盘锁管理器,但它也无法正常工作。有人可以给我锁手机的例子吗?
public class Keyguard extends Activity
{
Button btn;
KeyguardLock lock;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.btn);
KeyguardManager mgr = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
lock = mgr.newKeyguardLock(KEYGUARD_SERVICE);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
lock.reenableKeyguard();
}
});
}
}
这段代码将为你工作。
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = 0;
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
要锁定安卓设备,您必须拥有管理员权限。你必须注意三件事:1)DeviceAdminReceiver 类 2)清单文件 3)活动类,在其中调用 DevicePolicyManager 的锁定方法。请参阅此链接 http://developer.android.com/guide/topics/admin/device-admin.html