Android 新的鎖屏介面的實現

來源:互聯網
上載者:User

從Android
2.2開始,加入了一個新的鎖屏API
位於android.app.admin.DevicePolicyManager
包,DevicePolicyManager類的lockNow方法可以鎖住螢幕,查看Android原始碼發現其實是從IDevicePolicyManager實現的,整個AIDL介面
調用代碼為:

  1. private final IDevicePolicyManager mService;
  2. mService = IDevicePolicyManager.Stub.asInterface(
  3.                 ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
  4. if (mService != null) {
  5.             try {
  6.                 mService.lockNow();
  7.             } catch (RemoteException e) {
  8.                 Log.w(TAG, "Failed talking with device policy service", e);
  9.             }
  10. }

複製代碼

這裡
Android123提示大家傳統的方法加入<uses-permission
android:name="android.permission.DISABLE_KEYGUARD"></uses-
permission>許可權,使用下面代碼可以鎖住鍵盤,但螢幕不行

  1.   KeyguardManager km =    (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
  2.   KeyguardLock kl= km.newKeyguardLock(KEYGUARD_SERVICE);
  3.   kl.reenableKeyguard();

複製代碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.