Handling specific application actions after waking a sleep device
I store all application data in my db. I want to do different things when
- The app opens for the first time after the device wakes up from sleep
- The app opens for the 2nd or more time after waking up from sleep
How can i do this? eg,
- The camera opens after waking up the device - for the first time - my app will ask for a password
- the camera is open 2 times, I will not ask for a password
- whatsapp opens after waking up the device - for the first time - my app will ask for a password
- whatsapp opens 2nd time when i won't ask for password
+3
source to share
1 answer
Implement if-else
in Service
with BroadcastReceiver
, which will run every time the device is turned on, for example:
<receiver android:name="com.example.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
And don't forget to add permission:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
0
source to share