Reputation: 143
I m working on an app where i have to get the event or device state when device screen is on but not locked screen is not unlocked. Does any body has any idea about it. Thanks!!
Upvotes: 2
Views: 2697
Reputation: 551
You have three broadcasts available Intent.ACTION_SCREEN_OFF, Intent.ACTION_SCREEN_ON and Intent.ACTION_USER_PRESENT. First is pretty obvious. The other two are distinct in the way the user wakes the screen. If it is just a wake it is ACTION_SCREEN_ON, if it is followed by unlocking the screen Intent.ACTION_USER_PRESENT is launched too.
Make a broadcast receiver with a following intent filter:
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
Alternatively to get current state you can use Display.getState() and PowerManager.isInteractive()
Upvotes: 2