判断应用是否处于前台
程序员文章站
2022-05-03 12:08:07
private boolean isForeground() { ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List
private boolean isforeground() { activitymanager activitymanager = (activitymanager) getsystemservice(context.activity_service); list<activitymanager.runningappprocessinfo> processes = activitymanager.getrunningappprocesses(); if (processes == null || processes.isempty()) { return false; } for (activitymanager.runningappprocessinfo info : processes) { if (info.processname.equals(getpackagename()) && info.importance == activitymanager.runningappprocessinfo.importance_foreground) { return true; } } return false; }
上一篇: vuejs之路由应用之一