Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't succeed in achieving this feature by using these Flags, but I did succeed by using the <a href="http://developer.android.com/reference/android/os/PowerManager.WakeLock.html" rel="noreferrer">WakeLock</a> and <a href="http://developer.android.com/reference/android/app/KeyguardManager.KeyguardLock.html" rel="noreferrer">KeyguardLock</a>. Below is what I do:</p> <pre><code>public class DismissLock extends Activity { PowerManager pm; WakeLock wl; KeyguardManager km; KeyguardLock kl; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Log.i("INFO", "onCreate() in DismissLock"); pm = (PowerManager) getSystemService(Context.POWER_SERVICE); km=(KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); kl=km.newKeyguardLock("INFO"); wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE, "INFO"); wl.acquire(); //wake up the screen kl.disableKeyguard();// dismiss the keyguard setContentView(R.layout.main); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); wl.release(); //when the activiy pauses, we should realse the wakelock } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); wl.acquire();//must call this! } } </code></pre> <p>Of course, you still need to declare the permission in the manifest file.</p> <pre><code>&lt;uses-permission android:name="android.permission.WAKE_LOCK"/&gt; &lt;uses-permission android:name="android.permission.DISABLE_KEYGUARD"/&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload