Android, Detect when other apps are launched

2018-12-31 05:40发布

I'm trying to develop an app that prevents a user from getting to a specified app without a password. The scenario is...

  1. user clicks on "Email" app (for example)
  2. my app detects launch of an app
  3. my app confirms it is the "Email" app
  4. my app opens a view over the top, asking for a password
  5. user enters a password, if correct, my app disappears, leaving the "Email" app on top

I'm ok doing the rest of it, just part 2 is puzzling me, and after many days reading up on Broadcast Intents etc and trying to listen for "android.intent.action.MAIN" etc in my trial projects I can't seem to detect when an app other than mine is started.

Can anyone help? Am I going about it the right way, in looking for new apps broadcasting an intent to start, or should I be reading the system log for new intents, or doing something in native code?

Any pointers would help, even if you can't answer it fully I'll be able to do some more research. Thanks a lot. Ian

7条回答
人气声优
2楼-- · 2018-12-31 05:47

Perhaps you need a service, something that will run in the background constantly. Than have your service do what you said. Listen for the android.intent.action.MAIN also with the category android.intent.category.LAUNCHER. Then have that broadcast receiver override the onReceive method and do check to see the name of the application etc.

查看更多
登录 后发表回答