Search in sources :

Example 91 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method findDocTask.

ActivityManager.AppTask findDocTask() {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> tasks = am.getAppTasks();
    if (tasks != null) {
        for (int i = 0; i < tasks.size(); i++) {
            ActivityManager.AppTask task = tasks.get(i);
            ActivityManager.RecentTaskInfo recent = task.getTaskInfo();
            if (recent.baseIntent != null && recent.baseIntent.getComponent().getClassName().equals(DocActivity.class.getCanonicalName())) {
                return task;
            }
        }
    }
    return null;
}
Also used : ActivityManager(android.app.ActivityManager)

Example 92 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method setExclude.

void setExclude(boolean exclude) {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.AppTask> tasks = am.getAppTasks();
    int taskId = getTaskId();
    for (int i = 0; i < tasks.size(); i++) {
        ActivityManager.AppTask task = tasks.get(i);
        if (task.getTaskInfo().id == taskId) {
            task.setExcludeFromRecents(exclude);
        }
    }
}
Also used : ActivityManager(android.app.ActivityManager)

Example 93 with ActivityManager

use of android.app.ActivityManager in project android_frameworks_base by ResurrectionRemix.

the class ActivityTestMain method addAppRecents.

void addAppRecents(int count) {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.setComponent(new ComponentName(this, ActivityTestMain.class));
    for (int i = 0; i < count; i++) {
        ActivityManager.TaskDescription desc = new ActivityManager.TaskDescription();
        desc.setLabel("Added #" + i);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
        if ((i & 1) == 0) {
            desc.setIcon(bitmap);
        }
        int taskId = am.addAppTask(this, intent, desc, bitmap);
        Log.i(TAG, "Added new task id #" + taskId);
    }
}
Also used : Bitmap(android.graphics.Bitmap) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) ActivityManager(android.app.ActivityManager)

Example 94 with ActivityManager

use of android.app.ActivityManager in project LshUtils by SenhLinsh.

the class AppUtils method gc.

/**
     * 清理后台进程与服务
     *
     * @return 被清理的数量
     */
public static int gc(Context context) {
    long i = getDeviceUsableMemory(context);
    // 清理掉的进程数
    int count = 0;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    // 获取正在运行的service列表
    List<RunningServiceInfo> serviceList = am.getRunningServices(100);
    if (serviceList != null) {
        for (RunningServiceInfo service : serviceList) {
            if (service.pid == android.os.Process.myPid())
                continue;
            try {
                android.os.Process.killProcess(service.pid);
                count++;
            } catch (Exception e) {
                e.getStackTrace();
            }
        }
    }
    // 获取正在运行的进程列表
    List<RunningAppProcessInfo> processList = am.getRunningAppProcesses();
    if (processList != null) {
        for (RunningAppProcessInfo process : processList) {
            // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE的进程都是非可见进程,也就是在后台运行着
            if (process.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                // pkgList 得到该进程下运行的包名
                String[] pkgList = process.pkgList;
                for (String pkgName : pkgList) {
                    if (DEBUG) {
                    }
                    try {
                        am.killBackgroundProcesses(pkgName);
                        count++;
                    } catch (Exception e) {
                        // 防止意外发生
                        e.getStackTrace();
                    }
                }
            }
        }
    }
    if (DEBUG) {
    }
    return count;
}
Also used : RunningAppProcessInfo(android.app.ActivityManager.RunningAppProcessInfo) RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) ActivityManager(android.app.ActivityManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 95 with ActivityManager

use of android.app.ActivityManager in project LshUtils by SenhLinsh.

the class AppUtils method isServiceRunning.

/**
     * 检查服务是否正在运行
     */
public static boolean isServiceRunning(Context context, Class<? extends Service> service) {
    //获取Activity管理器
    ActivityManager manager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
    //获取运行中服务
    List<RunningServiceInfo> services = manager.getRunningServices(1000);
    String serviceName = service.getName();
    for (RunningServiceInfo info : services) {
        //获取每一条运行中的服务的类名并判断
        String name = info.service.getClassName();
        if (TextUtils.equals(serviceName, name)) {
            return true;
        }
    }
    return false;
}
Also used : RunningServiceInfo(android.app.ActivityManager.RunningServiceInfo) 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