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();

Thursday, January 20, 2011

Android Application Screen Orientation issues

Screen Orientation issues to know when designing Android Application

1. To design application in Portrait Mode only add screen orientation attribute in manifest.xml, make sure you add inside activity,

android:screenOrientation="portrait"

2. Sometimes views/Controls in the application initializes on change in Orientation. add android:configChanges in manifest.xml, inside activity attribute

android:configChanges="Orientation"

wish to manipulate with Keyboard use

android:configChanges="keyboardHidden|Orientation" this is more useful when application is installed on hard keyboard devices.