简体   繁体   English

阻止活动启动

[英]Prevent Activity From Launching

Is there a good way of preventing an activity from launching?是否有防止活动启动的好方法? I'd like to build either a whitelist or blacklist of applications, then prevent those instances from being started.我想建立应用程序的白名单或黑名单,然后阻止这些实例启动。

One potential solution is to poll the running tasks every so often and shut them down, but this seems like it could eat through a lot of battery.一种可能的解决方案是每隔一段时间轮询正在运行的任务并关闭它们,但这似乎会消耗大量电池。

Sorry, this is not supported with the SDK.抱歉,SDK 不支持此功能。

Ok so this doesnt count as a "GOOD WAY", could very well be as draining if not more so on your battery, but in line with your polling method:好的,所以这不算是“好方法”,如果不是更多的话,很可能会耗尽您的电池,但符合您的轮询方法:

you could create a service that monitors the log cat ( http://www.helloandroid.com/tutorials/reading-logs-programatically ) need permission in manifest:您可以创建一个监视日志猫的服务( http://www.helloandroid.com/tutorials/reading-logs-programatically )需要清单中的权限:

<uses-permission android:name="android.permission.READ_LOGS" />

then in your service something like (very crude):然后在您的服务中(非常粗略):

private void readLogAndKill(){
 try {
      Process process = Runtime.getRuntime().exec("logcat -d");
      BufferedReader bufferedReader = new BufferedReader(
      new InputStreamReader(process.getInputStream()));

      String line;
      while ((line = bufferedReader.readLine()) != null) {
        if (line.contains("Starting Activity")){
             if(line.contains("com.twitter.android"){
                  //kill twitter for example
              }
         }
      }

    } catch (IOException e) {
    }

}

there may be someway to catch the "Starting Activity" events - or filter the log as you read it for just those msgs.可能有某种方式可以捕获“开始活动”事件 - 或者在您阅读日志时过滤这些消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM