I\'m developing an app in which I need to do an action when the power button is pressed but unfortunately I cant handel the action of power button when it is pressed. I trie
I don't know what you intend to do, but you could use a BroadcastReceiver and listen for the android.intent.action.SCREEN_OFF or Intent.ACTION_SCREEN_OFF which is sent when power button is pressed (and screen is on).
Unfortunately this intent will be sent when the screen times out too. But I think you can prevent the phone from being locked (while in an application) like this
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);