Android一键锁屏开发全过程
2013-03-22 13:24
162 查看
一、项目简介:
项目:《Android一键锁屏》
开发周期:4天
代码量:100行
————————————————————————
二、项目流程:
四、项目预览
请求权限界面
锁屏成功
五、附注
程序运行在android2.2以上平台(含2.2)
项目:《Android一键锁屏》
开发周期:4天
代码量:100行
————————————————————————
二、项目流程:
001 | 三、项目代码 |
002 | 1 、主程序代码: |
003 | Java代码 |
004 | private DevicePolicyManager policyManager; |
005 | private ComponentName componentName; |
006 |
007 | @Override |
008 | protected void onCreate(Bundle savedInstanceState){ |
009 | super .onCreate(savedInstanceState); |
010 | setContentView(R.layout.locklayout); |
011 |
012 | //获取设备管理服务 |
013 | policyManager =(DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE); |
014 |
015 | //AdminReceiver 继承自DeviceAdminReceiver |
016 | componentName = new ComponentName( this , AdminReceiver. class ); |
017 |
018 | mylock(); |
019 | // |
020 | android.os.Process.killProcess(android.os.Process.myPid()); |
021 |
022 | } |
023 |
024 | 2 、其中,mylock()为: |
025 | Java代码 |
026 | private void mylock(){ |
027 |
028 | boolean active |
029 | if (!active){ //若无权限 |
030 | activeManage(); //去获得权限 |
031 | policyManager.lockNow(); //并锁屏 |
032 | } |
033 | if (active) |
034 | policyManager.lockNow(); //直接锁屏 |
035 | } |
036 | } |
037 | 3 、activeManage()代码为: |
038 | Java代码 |
039 | private void activeManage() |
040 | // |
041 | Intent new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); |
042 |
043 | //权限列表 |
044 | intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, |
045 |
046 | //描述(additional |
047 | intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "------ ); |
048 |
049 | startActivityForResult(intent, 0 ); |
050 | } |
051 |
052 | 4 、AndroidManifest.xml |
053 | Java代码 |
054 | <?xml version= "1.0" encoding= "utf-8" ?> |
055 | <manifest xmlns:android= "http://schemas.android.com/apk/res/android" |
056 | package = "cn.hnu" |
057 | android:versionCode= "1" |
058 | android:versionName= "1.0" > |
059 | <application android:icon= "@drawable/icon" android:label= "@string/app_name" > |
060 | <activity android:name= ".LockFirst" |
061 | android:label= "@string/app_name" > |
062 | <intent-filter> |
063 | <action android:name= "android.intent.action.MAIN" /> |
064 | <category android:name= "android.intent.category.LAUNCHER" /> |
065 | </intent-filter> |
066 | </activity> |
067 | <!-- |
068 | <receiver android:name= ".AdminReceiver" |
069 | android:label= "@string/app_name" |
070 | android:description= "@string/app_name" |
071 | android:permission= "android.permission.BIND_DEVICE_ADMIN" > |
072 | <meta-data android:name= "android.app.device_admin" |
073 | android:resource= "@xml/lock_screen" /> |
074 | <intent-filter> |
075 | <action |
076 | android:name= "android.app.action.DEVICE_ADMIN_ENABLED" /> |
077 | </intent-filter> |
078 | </receiver> |
079 | </application> |
080 |
081 |
082 | </manifest> |
083 | 5 、其中lock_screen.xml(lock_screen.xml文件放在res/xml文件夹下)代码为: |
084 | Java代码 |
085 | <?xml version= "1.0" encoding= "UTF-8" ?> |
086 | <device-admin |
087 | xmlns:android= "http://schemas.android.com/apk/res/android" > |
088 | <uses-policies> |
089 | <!-- |
090 | <force-lock |
091 | <!-- |
092 | <wipe-data |
093 | <!-- |
094 | <reset-password |
095 | <!-- |
096 | <limit-password |
097 | <!-- |
098 | <watch-login |
099 | </uses-policies> |
100 | </device-admin> |
请求权限界面
锁屏成功
五、附注
程序运行在android2.2以上平台(含2.2)
相关文章推荐
- Android一键锁屏开发全过程
- Android一键锁屏开发全过程…
- Android一键锁屏开发全过程【源码+附图】
- android开发 华为手机锁屏存活,开机自启动,一键不清理,手动杀死自动起来
- android 一键锁屏 开发
- 【拯救电源键】最详尽的android开发一键锁屏实例 提供免费源码+apk
- 【Android开发小记--10】一键锁屏功能实现
- 【Android应用开发】-(10)一个应用程序开发的蜕变过程
- Android开发过程中调试的快捷键
- Android锁屏、重启、关机开发!简单直接
- Android2.2浏览器插件的surface加载过程的改变  -  棒槌网@Android开发论坛 - Powered by phpwind
- Android开发过程中需要注意的细节
- Android 闹钟 开发过程记录(六)
- android 一键锁屏
- android 实现一键锁屏功能
- 开发过程中遇到的问题总结--qt for android
- Android心得2.2--第一个应用程序开发过程及屏幕大小与分辨率详解
- android 开发过程中的快捷键和技巧
- Android程序之一键锁屏
- Android底层连接库的编译过程及其Android NDK开发实例