Android, Detect when other apps are launched

后端 未结 7 1048
臣服心动
臣服心动 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条回答
  •  遇见更好的自我
    2020-11-22 03:11

    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.

提交回复
热议问题