简体   繁体   English

android广播接收器检测应用程序在后台更改

[英]android broadcast receiver to detect app in background change

Is there anyway to capture when other application goes into background? 当其他应用程序进入后台时,是否有捕获? Any broadcast receiver we can register to receive that event? 我们可以注册接收该事件的任何广播接收器吗?

出于明显的隐私原因,没有关于前往或离开前台的活动的广播Intent

You can write a backgroung service that periodically monitors the running services and if a new service comes up raises a flag. 您可以编写一个backgroung服务,定期监视正在运行的服务,如果出现新服务则会引发一个标志。 Use this to get the list of running services: 使用它来获取正在运行的服务列表:

    public List<String> getRunningServices(Context context){
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> serviceList = activityManager
                .getRunningServices(Integer.MAX_VALUE);
        List<String> rServices = new ArrayList<String>();
        for (int i = 0; i < serviceList.size(); i++) {
            RunningServiceInfo serviceInfo = serviceList.get(i);
            ComponentName serviceName = serviceInfo.service;            
            rServices.add(serviceName.getClassName());      
        }
        return rServices;
   }

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

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