Android, Detect when other apps are launched

后端 未结 7 1035
臣服心动
臣服心动 2020-11-22 02:41

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 exa
7条回答
  •  -上瘾入骨i
    2020-11-22 03:21

    A gimmicky way to do it is have a service with a timed loop that checks

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
    List runningAppProcessInfo = am.getRunningAppProcesses();
    

    You run through that list to look at what is running on the phone. Now you can identify them with ids and processName, so for standard activity this is easy for custom ones well unless you stop them all its hard to discriminate...

    Note: this isnt a list of whats is actually on the screen, just a list of whats is running...kinda nullifying your goal maybe but at least you will know when something is starting to run... it will keep being in that list even when in background though.

    For the password thing you can just start your activity when you found an app thats protected or whatever.

提交回复
热议问题