use of android.app.ActivityManager in project android-common by Trinea.
the class AppUtils method isApplicationInBackground.
/**
* whether application is in background
* <ul>
* <li>need use permission android.permission.GET_TASKS in Manifest.xml</li>
* </ul>
*
* @param context
* @return if application is in background return true, otherwise return false
*/
public static boolean isApplicationInBackground(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> taskList = am.getRunningTasks(1);
if (taskList != null && !taskList.isEmpty()) {
ComponentName topActivity = taskList.get(0).topActivity;
if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
use of android.app.ActivityManager in project android-common by Trinea.
the class PackageUtils method isTopActivity.
/**
* whether the app whost package's name is packageName is on the top of the stack
* <ul>
* <strong>Attentions:</strong>
* <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
* </ul>
*
* @param context
* @param packageName
* @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
* stack
*/
public static Boolean isTopActivity(Context context, String packageName) {
if (context == null || StringUtils.isEmpty(packageName)) {
return null;
}
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
if (ListUtils.isEmpty(tasksInfo)) {
return null;
}
try {
return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
use of android.app.ActivityManager in project LuaViewSDK by alibaba.
the class AndroidUtil method getTotalMemorySize.
/**
* 获取所有的内存大小(in k)
*
* @param context
* @return
*/
@TargetApi(16)
public static Long getTotalMemorySize(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return mi != null ? mi.totalMem : null;
} else {
return null;
}
}
use of android.app.ActivityManager in project LuaViewSDK by alibaba.
the class AndroidUtil method getAvailMemorySize.
/**
* 获取可用的内存大小(in k)
*
* @param context
* @return
*/
public static Long getAvailMemorySize(Context context) {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
return mi != null ? mi.availMem : null;
}
use of android.app.ActivityManager in project atlas by alibaba.
the class KernalVersionManager method killChildProcesses.
private void killChildProcesses(Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> a = am.getRunningAppProcesses();
for (int i = 0; i < a.size(); i++) {
ActivityManager.RunningAppProcessInfo b = a.get(i);
if (b.processName.contains(context.getPackageName() + ":")) {
android.os.Process.killProcess(b.pid);
continue;
}
}
} catch (Exception e) {
}
}
Aggregations