Android 锁定屏幕 不可解锁
2017-04-25 17:09
477 查看
Android锁定屏幕
这个玩意只是在MDM上有所应用,通过后台发送指令到Android上,或者是Android程序本身检测满足某一条件的时候,对Android手机进行锁屏操作,当前这种方法,只能通过硬件重启的方式解除锁屏,即音量键+锁屏键
好了,闲言少叙,这个操作主要涉及到下面这个类
LockScreenUtil 主要类
package com.example.demo; import android.content.Context; import android.graphics.PixelFormat; import android.graphics.Point; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.Button; public class LockScreenUtil { Point mLpSize; Button mBtnUnlock; ViewGroup mView; final WindowManager mWindowManager; final WindowManager.LayoutParams mLp; public LockScreenUtil(Context mContext){ mView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.lock_screen_view, null); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); mLp = new WindowManager.LayoutParams(); mBtnUnlock = (Button)mView.findViewById(R.id.btn_unlock); mBtnUnlock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { show(false); } }); initLp(); } private void initLp(){ mLp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;// TYPE_SYSTEM_ALERT; mLp.format = PixelFormat.RGBA_8888; mLp.flags |= WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; mLp.systemUiVisibility = View.STATUS_BAR_HIDDEN; mLp.width = WindowManager.LayoutParams.MATCH_PARENT; mLp.height = WindowManager.LayoutParams.MATCH_PARENT; } public void show(boolean flag){ if (flag){ mWindowManager.addView(mView, mLp); } else { mWindowManager.removeView(mView); } } }
Activity中涉及到的东西就相对较少了
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBtnLock = (Button)findViewById(R.id.btn); mLockScreen = new LockScreen(this); mBtnLock.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mLockScreen.show(true); } }); }
lock_screen_view.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/btn_unlock" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="lock" /> </LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="LOck" > </Button> </LinearLayout>
最后不要忘记权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
运行之后点击Lock 即可锁定屏幕,当然程序还不完美,还需继续修改完善,有时间继续更
相关文章推荐
- Android屏幕点亮(常亮)及屏幕解锁和锁定 全屏显示
- Android设备屏幕锁定/解锁/屏幕点亮监听
- Android点亮屏幕或屏幕解锁和锁定以及其他相关权限实现代码
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android设备屏幕锁定/解锁/屏幕点亮监听
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android判断屏幕状态与屏幕解锁和锁定
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android闹钟程序&屏幕点亮(常亮)及屏幕解锁和锁定
- Android点亮屏幕或屏幕解锁和锁定
- Android屏幕点亮(常亮)及屏幕解锁和锁定
- Android设备屏幕锁定/解锁/屏幕点亮监听
- Android屏幕锁定实例源码详解教程二
- Android屏幕锁定详解完整版(二) 推荐
- Android屏幕解锁和点亮
- Android屏幕解锁和点亮
- Rexsee API介绍:Android屏幕锁定,Keyguard函数与扩展源码
- android 如何做屏幕自适应, 在不可调整分辨率的情况下(据说某些新出的机器可调,也就是说大部分机器分辨率都不可调的)
- android 点亮屏幕与解锁