package cn.itcast.lockscreen;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
/**
* device admin : ��ȡ�豸�ij�������ԱȨ��
*
* @author zehua
*
*/
public class LockscreenActivity extends Activity implements OnClickListener {
private static final String LOCK_TAG = null;
private Button bt_lock;
private Button bt_wipe;
private Button bt_close;
private Button bt_uninstall;
DevicePolicyManager policyManager;
ComponentName componentName;
private final int requestCode = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bt_lock = (Button) this.findViewById(R.id.button1);
bt_wipe = (Button) this.findViewById(R.id.button2);
bt_close = (Button) this.findViewById(R.id.button3);
bt_uninstall = (Button) this.findViewById(R.id.button4);
bt_lock.setOnClickListener(this);
bt_wipe.setOnClickListener(this);
bt_close.setOnClickListener(this);
bt_uninstall.setOnClickListener(this);
policyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
componentName = new ComponentName(this, MyAdmin.class);
if (!policyManager.isAdminActive(componentName)) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, componentName);
startActivity(intent);
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1: // 显示出要输入密码才能进入
policyManager.resetPassword("1234", 0);
policyManager.lockNow();
break;
case R.id.button2: // 清除数据
policyManager.wipeData(0);
break;
case R.id.button3: // 锁屏并关闭屏幕
systemLock();
break;
case R.id.button4: // 锁屏并关闭屏幕
UninstallActivity();
break;
}
}
/**
* 锁屏并关闭屏幕
*/
private void systemLock()
{
if (this.policyManager.isAdminActive(this.componentName))
{
Window localWindow = getWindow();
WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();
localLayoutParams.screenBrightness = 0.05F;
localWindow.setAttributes(localLayoutParams);
this.policyManager.lockNow();
}
finish();
}
/**
* 停用设备管理器并卸载程序
*/
private void UninstallActivity(){
this.policyManager.removeActiveAdmin(this.componentName);
startActivity(new Intent("android.intent.action.DELETE", Uri.parse("package:cn.itcast.lockscreen")));
finish();
}
}
金枝玉叶9
- 粉丝: 198
- 资源: 7637
最新资源
- 共创在线考试系统(JSP+SERVLET)130223.rar
- 俄罗斯方块(java+applet)130228.rar
- 会员管理系统(struts+hibernate+spring)130226.rar
- 会员管理系统(struts+hibernate+spring).rar
- 基于J2EE在分布式环境下的底层结构(外文翻译+文献综述).rar
- 基于JSP的畅想空间电子商务系统.rar
- 基于JSP的网上购物系统的设计与实现(源代码+论文).rar
- 基于JSP的房产中介系统的设计与实现(源代码+论文).rar
- 基于JSP电子商务系统?(论文).rar
- 基于jsp的新闻发布系统(论文).rar
- 基于matlab的数字图像分割技术研究及实现(论文).rar
- 基于jsp网上书店(源代码+论文).rar
- 计算器(java+applet)130228.rar
- 家庭理财系统(java+applet)130227.rar
- 教材订购系统(jsp+servlet+mysql).rar
- 教材订购系统(jsp+servlet+mysql)130226.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈