<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" > <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="139dp"
android:onClick="lockScreen"
android:text="一键锁屏" /> <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="63dp"
android:onClick="activeAdmin"
android:text="激活设备管理器" /> <Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:onClick="unInstall"
android:text="卸载程序" /> <Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="44dp"
android:onClick="clearData"
android:text="清除数据" /> </RelativeLayout>

清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima52.admin"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" /> <application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.itheima52.admin.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- <string name="sample_device_admin_description">有了超级设备管理器,可以一键锁屏,清除数据等等</string>
<string name="sample_device_admin">超级设备管理器</string> -->
<receiver
android:name=".AdminReceiver"
<!--
import android.app.admin.DeviceAdminReceiver;
public class AdminReceiver extends DeviceAdminReceiver {
}
-->
android:description="@string/sample_device_admin_description" receive的描述
android:label="@string/sample_device_admin" receive的说明
android:permission="android.permission.BIND_DEVICE_ADMIN" > 权限
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" /> 需要的xml文件,表示有哪些功能
<!--
res/xml/device_admin_sample.xml
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
<uses-policies>
<limit-password />
<watch-login />
<reset-password />
<force-lock /> 锁频
<wipe-data /> 清楚数据
<expire-password />
<encrypted-storage />
<disable-camera />
</uses-policies>
</device-admin>
-->
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
</application>
</manifest>
package com.itheima52.admin;

import android.app.Activity;
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.view.View;
import android.widget.Toast; public class MainActivity extends Activity { private DevicePolicyManager mDPM;//用来锁频,激活密码,清楚数据,先要激活设备管理器
private ComponentName mDeviceAdminSample;// 设备管理组件,用来激活设备管理器 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);// 获取设备策略服务
mDeviceAdminSample = new ComponentName(this, AdminReceiver.class);// 设备管理组件 // mDPM.lockNow();// 立即锁屏
// finish();
} // 激活设备管理器, 也可以在设置->安全->设备管理器中手动激活(要使用超级设备管理器就要先激活设备管理器)。
public void activeAdmin(View view) {
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,mDeviceAdminSample);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"哈哈哈, 我们有了超级设备管理器, 好NB!");
startActivity(intent);
} // 一键锁屏
public void lockScreen(View view) {
if (mDPM.isAdminActive(mDeviceAdminSample)) {// 判断设备管理器是否已经激活
mDPM.lockNow();// 立即锁屏,调用lockNow(),先要激活设备管理器
mDPM.resetPassword("123456", 0);//激活密码,先要激活设备管理器
} else {
Toast.makeText(this, "必须先激活设备管理器!", Toast.LENGTH_SHORT).show();
}
} public void clearData(View view) {
if (mDPM.isAdminActive(mDeviceAdminSample)) {// 判断设备管理器是否已经激活
mDPM.wipeData(0);// 清除数据,恢复出厂设置
} else {
Toast.makeText(this, "必须先激活设备管理器!", Toast.LENGTH_SHORT).show();
}
} public void unInstall(View view) {
mDPM.removeActiveAdmin(mDeviceAdminSample);// 取消设备管理权限 // 卸载程序
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivity(intent);
}
}

android133 360 06 一键锁频,清楚数据的更多相关文章

  1. android DevicePolicyManager实现一键锁屏

    本文章一部分资料来源于网上 1.实现一键锁屏关键是DevicePolicyManager这个类,然后使用lockNow():方法. 2.DevicePolicyManager类,可以让你的做软件获得系 ...

  2. Android Device Administration 设备管理器——实现一键锁屏

    Android Device Administration 设备管理器--实现一键锁屏 最近研究了一下安全这一块的内容,当然,我是比较水的,所以也拿不出什么好知识点,但是有一些冷门的东西我还是可以聊聊 ...

  3. Android一键锁屏APP

    题记: 这个app完全是拾人牙慧,作为练手用的,其实没有什么原创的东西.当然,博客还是我自己写的,记录下来,对自己也算是一种成长吧. 转载请注明原文地址: http://www.cnblogs.com ...

  4. 【WP 8.1开发】一键锁屏

    在WP8的时候,关于如何关闭屏幕,国内外都有不少文章了,大家有兴趣地可以搜搜,很多,我就不给链接了,因为稍后我的例子中会有. 其实,关闭屏幕是调用了未开放的API,正因为这个API未开放的,不敢保证所 ...

  5. XC一键锁屏应用

    XC一键锁屏,一键Android锁屏应用,彻底解放开关机键~ 下载地址: http://download.csdn.net/detail/jczmdeveloper/7329447

  6. Android简易实战教程--第六话《开发一键锁屏应用2·完成》

    转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/51885687点击打开链接 上一篇,初步开发了这个应用,功能都有了(见http:// ...

  7. Android简易实战教程--第五话《开发一键锁屏应用》

    转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/51860900 点击打开链接 Device Administration 对于这个应 ...

  8. Android一键锁屏源码

    APK下载 源程序下载 锁屏流程如下(参考于Android一键锁屏开发全过程[源码][附图]) 源码参考于一键锁屏 源码 一共有2个Java文件: package com.example.onekey ...

  9. Android锁屏后数据改变的解决方案

    如果一个界面设置成横屏,那么锁屏再开启之后,会重新执行一遍onCreate()方法.对于这个问题的解决方案如下: 只需要在Menifest文件的activity相应标签下添加这行代码即可: andro ...

随机推荐

  1. UVa 658 (Dijkstra) It's not a Bug, it's a Feature!

    题意: 有n个BUG和m个补丁,每个补丁用一个串表示打补丁前的状态要满足的要求,第二个串表示打完后对补丁的影响,还有打补丁所需要的时间. 求修复所有BUG的最短时间. 分析: 可以用n个二进制位表示这 ...

  2. mysql slave 错误解决

    执行CHANGE MASTER TO master_host............后报错 ERROR 1201 (HY000): Could not initialize master info s ...

  3. Windows 之间用rsync同步数据(cwRsyncServer配置)

    rsync是一款优秀的数据同步软件,在跨服务器,跨机房,跨国备份服务器的首选工具,下面就来介绍下如何配置安装cwRsyncServer很大多数软件一样是B/C架构,cwRsyncServer是rsyn ...

  4. 使用BusyBox制作Linux根文件系统

    STEP 1:构建目录结构 创建根文件系统目录,主要包括以下目录/dev  /etc /lib  /usr  /var /proc /tmp /home /root /mnt /bin  /sbin  ...

  5. 数学(扩展欧几里得算法):HDU 5114 Collision

    Matt is playing a naive computer game with his deeply loved pure girl. The playground is a rectangle ...

  6. 29、activity横竖屏切换细节问题

    1 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import andro ...

  7. HDU 5618 Jam's problem again CDQ分治 BC ROUND 70

    题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z 分析:(官方题解奉上)很 ...

  8. Js 与 TextArea

    当给一个js变量赋值一个有换行的值得时候,就会报错: <!DOCTYPE HTML> <html> <head> <script src="http ...

  9. HIbernate学习笔记(五) 关系映射之一对多与多对一

    三.       多对一 –单向 场景:用户和组:从用户角度来,多个用户属于一个组(多对一 关联) 使用hibernate开发的思路:先建立对象模型(领域模型),把实体抽取出来. 目前两个实体:用户和 ...

  10. Eclipse Class Decompiler影响class默认打开方式,重新设置Eclipse默认源码打开方式

    安装Eclipse Class Decompiler插件后,Eclipse中的默认源码打开方式被修改为Eclipse Class Decompiler 这不是我喜欢的,因为我希望,源码从网络中获取,当 ...