Search in sources :

Example 46 with ActivityManager

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;
}
Also used : ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo)

Example 47 with ActivityManager

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;
    }
}
Also used : ActivityManager(android.app.ActivityManager) RunningTaskInfo(android.app.ActivityManager.RunningTaskInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 48 with ActivityManager

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;
    }
}
Also used : ActivityManager(android.app.ActivityManager) TargetApi(android.annotation.TargetApi)

Example 49 with ActivityManager

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;
}
Also used : ActivityManager(android.app.ActivityManager)

Example 50 with ActivityManager

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) {
    }
}
Also used : ActivityManager(android.app.ActivityManager)

Aggregations

ActivityManager (android.app.ActivityManager)339 Intent (android.content.Intent)44 Context (android.content.Context)33 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)30 ComponentName (android.content.ComponentName)26 PackageManager (android.content.pm.PackageManager)23 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)18 IActivityManager (android.app.IActivityManager)16 ConfigurationInfo (android.content.pm.ConfigurationInfo)16 IOException (java.io.IOException)16 RunningServiceInfo (android.app.ActivityManager.RunningServiceInfo)15 View (android.view.View)15 ImageView (android.widget.ImageView)15 ArrayList (java.util.ArrayList)15 Point (android.graphics.Point)14 TextView (android.widget.TextView)14 RunningTaskInfo (android.app.ActivityManager.RunningTaskInfo)13 ResolveInfo (android.content.pm.ResolveInfo)12 RemoteException (android.os.RemoteException)12 TargetApi (android.annotation.TargetApi)11