Pages

Get it free, Try now

Free Cell Phones

Thursday, February 3, 2011

Screen ON And Unlock keypad

Screen ON: Required when activity is in foreground and performing long running task
Use below code snippet And add "android.permission.WAKE_LOCK" in app manifest

PowerManager powermgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = powermgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wakelock.acquire();
// call long running task
...
..
wakelock.release();


Unlock keypad: Required when using intents. example: Making a phone call with user activity and after completing phone call user acitivity shall not be held with a keylock

Use below code snippet inside Onresume() method of the activity. And add "android.permission.DISABLE_KEYGUARD" in app manifest
public void checkKeypadLock()
{
KeyguardManager Keylockmgr = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
Keylockmgr.newKeyguardLock("My Tag").disableKeyguard();
}



Complete Usage of Disabling and Reenabling keyguard on Android

if (mKeyguardManager == null) {
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
mKeyguardLock1 = mKeyguardManager.newKeyguardLock("QApp");
mKeyguardEnabled = true;
}

PowerManager powermgr = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = powermgr.newWakeLock(PowerManager.FULL_WAKE_LOCK| PowerManager.ON_AFTER_RELEASE| PowerManager.ACQUIRE_CAUSES_WAKEUP,"QApp");

wakelock.acquire();

if (mKeyguardEnabled) {
mKeyguardLock1.disableKeyguard();//


if(mProductID == 1)
retval = mCalculator.Calc(mcalcJob,isOnline);
else if(mProductID == 2)
retval = m_pCalculator.Calc(mcalcJob,isOnline);



mprogressDialog.dismiss();
mHandler.post(updateResults);

// ON sony ericsson the keylock is very quick, so we wait for 3Sec before reenabling keyguard only on Xperia 10i
if(Build.MANUFACTURER.startsWith("Sony"))
{
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
wakelock.release();
mKeyguardLock1.reenableKeyguard();

9 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..

    rpa training in Chennai | best rpa training in chennai

    rpa training in pune

    rpa online training | rpa training in bangalore

    ReplyDelete
  4. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    Data Science training in rajaji nagar | Data Science with Python training in chenni
    Data Science training in electronic city | Data Science training in USA
    Data science training in pune | Data science training in kalyan nagar

    ReplyDelete
  5. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    python training in velachery
    python training institute in chennai

    ReplyDelete
  6. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 

    best rpa training in chennai | rpa online training |
    rpa training in chennai |
    rpa training in bangalore
    rpa training in pune

    ReplyDelete
  7. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

    ReplyDelete