Android, Detect when other apps are launched Android, Detect when other apps are launched android android

Android, Detect when other apps are launched


I think we can use logcat and analyze it's output.

In all similar programs I have found this permission :

android.permission.READ_LOGS

It means all of them use it but it seems the program starts and after that our program (app protector) will start and bring front.

Use below code :

try    {        Process mLogcatProc = null;        BufferedReader reader = null;        mLogcatProc = Runtime.getRuntime().exec(new String[]{"logcat", "-d"});        reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));        String line;        final StringBuilder log = new StringBuilder();        String separator = System.getProperty("line.separator");         while ((line = reader.readLine()) != null)        {            log.append(line);            log.append(separator);        }        String w = log.toString();        Toast.makeText(getApplicationContext(),w, Toast.LENGTH_LONG).show();    }    catch (Exception e)     {        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();    }

And do not forget to add it's permission in Manifest file.


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

ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);List<ActivityManager.RunningAppProcessInfo> 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 appthats protected or whatever.


I think and hope this is not possible. Consider how easily such functionality could be abused by malicious software. You can listen to intents directed at you, and those that are broadcast, but application launching should not be a broadcast event.

What you may be able to do is replace the launcher. If the user agrees to it.