0

I am working on a Locker kind of app. My requirement is to open up a password screen when user goes to start specific applications (which are selected by user previously in my application.) I show the user a list of all applications with a Toggle button to lock / unlock. I am saving the preferences of the user in local sqlite database.

Main issue is how to get notified when the user starts one of those applications.

I went through this, this, this, this and many other vague posts already.

So now, we need system privileges for all 3 of these permissions:

<uses-permission android:name="android.permission.GET_TOP_ACTIVITY_INFO"/>
<uses-permission
    android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_LOGS"/>

I cannot make my app system app. It should behave as a normal user app. So this option is not useful.

The question is: Is there any other option to do this without rooted device / system privileged application? If so, please provide me a few guidelines I can follow.

Ana
  • 166
  • 1
  • 16

1 Answers1

0

It should be possible to build something like this using the features of AccessibilityService. You would have to register your app as an AccessibilityService and you would be notified of all events. You could react on "window content changed" or "window state changed" events and then query the Android framework to get information about which window changed and what app the window belongs to and react accordingly. This is probably a lot of work and probably a lot of trial-and-error work to get it to do what you want.

David Wasser
  • 93,459
  • 16
  • 209
  • 274