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
- 粉丝: 194
- 资源: 7637
最新资源
- C语言-leetcode题解之28-implement-strstr.c
- C语言-leetcode题解之27-remove-element.c
- C语言-leetcode题解之26-remove-duplicates-from-sorted-array.c
- C语言-leetcode题解之24-swap-nodes-in-pairs.c
- C语言-leetcode题解之22-generate-parentheses.c
- C语言-leetcode题解之21-merge-two-sorted-lists.c
- java-leetcode题解之Online Stock Span.java
- java-leetcode题解之Online Majority Element In Subarray.java
- java-leetcode题解之Odd Even Jump.java
- 计算机毕业设计:python+爬虫+cnki网站爬
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈