当前位置: 首页>>代码示例>>Java>>正文


Java ActivityManager.RunningTaskInfo方法代码示例

本文整理汇总了Java中android.app.ActivityManager.RunningTaskInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.RunningTaskInfo方法的具体用法?Java ActivityManager.RunningTaskInfo怎么用?Java ActivityManager.RunningTaskInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.ActivityManager的用法示例。


在下文中一共展示了ActivityManager.RunningTaskInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAppIsInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isAppIsInBackground(Context context) {
    boolean isInBackground = true;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                for (String activeProcess : processInfo.pkgList) {
                    if (activeProcess.equals(context.getPackageName())) {
                        isInBackground = false;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            isInBackground = false;
        }
    }
    return isInBackground;
}
 
开发者ID:NarendraSickarwar,项目名称:FirebasePost,代码行数:24,代码来源:PostTableService.java

示例2: isAppIsInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isAppIsInBackground(Context context) {
    boolean isInBackground = true;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                for (String activeProcess : processInfo.pkgList) {
                    if (activeProcess.equals(context.getPackageName())) {
                        isInBackground = false;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            isInBackground = false;
        }
    }
    return isInBackground;
}
 
开发者ID:anandwana001,项目名称:Tech-Jalsa,代码行数:24,代码来源:NotificationUtils.java

示例3: isAppIsInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Method check if app is in background or in foreground
 *
 * @param context this contentx
 * @return true if app is in background or false if app in foreground
 */

private boolean isAppIsInBackground(Context context) {
    boolean isInBackground = true;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                for (String activeProcess : processInfo.pkgList) {
                    if (activeProcess.equals(context.getPackageName())) {
                        isInBackground = false;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            isInBackground = false;
        }
    }

    return isInBackground;
}
 
开发者ID:codingdojoangola,项目名称:cda-app,代码行数:32,代码来源:FirebaseService.java

示例4: isTopActivity

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断某个包名是否运行在顶层
 *
 * @param context
 * @param packageName
 * @return
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || TextUtils.isEmpty(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (tasksInfo == null || tasksInfo.isEmpty()) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:25,代码来源:Kits.java

示例5: isApplicationBroughtToBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 慎重使用此函数<br/>
 * GET_TASK was deprecated in API level 21. No longer enforced
 */
public static boolean isApplicationBroughtToBackground(final Context context) {
	try {
		ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
		if (!tasks.isEmpty()) {
			ComponentName topActivity = tasks.get(0).topActivity;
			if (!topActivity.getPackageName().equals(context.getPackageName())) {
				return true;
			}
		}
	}catch (Exception ex){
		ex.printStackTrace();
	}
	return false;
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:20,代码来源:ActivityHelper.java

示例6: isAppIsInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * Method checks if the app is in background or not
 */
public static boolean isAppIsInBackground(Context context) {
    boolean isInBackground = true;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses();
        for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) {
            if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                for (String activeProcess : processInfo.pkgList) {
                    if (activeProcess.equals(context.getPackageName())) {
                        isInBackground = false;
                    }
                }
            }
        }
    } else {
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
        ComponentName componentInfo = taskInfo.get(0).topActivity;
        if (componentInfo.getPackageName().equals(context.getPackageName())) {
            isInBackground = false;
        }
    }

    return isInBackground;
}
 
开发者ID:safaricom,项目名称:LNMOnlineAndroidSample,代码行数:28,代码来源:NotificationUtils.java

示例7: isRunningApp

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断程序是否在运行
 */
public static boolean isRunningApp(Context context, String packageName) {
    boolean isAppRunning = false;
    List<ActivityManager.RunningTaskInfo> list = getAllRunningTask(context);
    for (ActivityManager.RunningTaskInfo info : list) {
        if (info.topActivity.getPackageName().equalsIgnoreCase(packageName)
                && info.baseActivity.getPackageName().equalsIgnoreCase(packageName)) {
            isAppRunning = true;
            break;
        }
    }
    return isAppRunning;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:16,代码来源:CmdUtil.java

示例8: bring2Front

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 将当前应用运行到前台
 */
private void bring2Front(Context context) {
    ActivityManager activtyManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfos = activtyManager.getRunningTasks(3);
    for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos) {
        if (context.getPackageName().equals(runningTaskInfo.topActivity.getPackageName())) {
            activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
            return;
        }
    }
}
 
开发者ID:xmlxin,项目名称:ReplyMessage,代码行数:14,代码来源:SystemUtil.java

示例9: isAppAtBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断当前应用程序处于前台还是后台
 * @param context
 * @return
 *  true:前台   false:后台
 */
private boolean isAppAtBackground(final Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:18,代码来源:WindowService.java

示例10: isForeground

import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isForeground() {
    ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
    if (list != null && list.size() > 0) {
        ComponentName cpn = list.get(0).topActivity;
        if (MainActivity.class.getName().contains(cpn.getClassName())) {
            return true;
        }
    }

    return false;
}
 
开发者ID:ynztlxdeai,项目名称:TextReader,代码行数:13,代码来源:RecommendFragment.java

示例11: bring2Front

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
    * 将当前应用运行到前台
    */
   private void bring2Front()
   {
       ActivityManager activtyManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
       List<ActivityManager.RunningTaskInfo> runningTaskInfos = activtyManager.getRunningTasks(3);
       for (ActivityManager.RunningTaskInfo runningTaskInfo : runningTaskInfos)
{
           if (this.getPackageName().equals(runningTaskInfo.topActivity.getPackageName()))
    {
               activtyManager.moveTaskToFront(runningTaskInfo.id, ActivityManager.MOVE_TASK_WITH_HOME);
               return;
           }
       }
   }
 
开发者ID:stytooldex,项目名称:stynico,代码行数:17,代码来源:AppCompatDlalog.java

示例12: isAppBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断当前App处于前台还是后台
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.GET_TASKS"/>}</p>
 * <p>并且必须是系统应用该方法才有效</p>
 *
 * @param context 上下文
 * @return {@code true}: 后台<br>{@code false}: 前台
 */
public static boolean isAppBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    @SuppressWarnings("deprecation")
    List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:ChunweiDu,项目名称:Utils,代码行数:21,代码来源:AppUtil.java

示例13: isApplicationInBackground

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 判断当前应用是否运行在后台
 *
 * @param context
 * @return
 */
public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.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;
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:18,代码来源:Kits.java

示例14: call

import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
	List<ActivityManager.RunningTaskInfo> runningTaskInfos = (List<ActivityManager.RunningTaskInfo>) method
			.invoke(who, args);
	for (ActivityManager.RunningTaskInfo info : runningTaskInfos) {
		AppTaskInfo taskInfo = VActivityManager.get().getTaskInfo(info.id);
		if (taskInfo != null) {
			info.topActivity = taskInfo.topActivity;
			info.baseActivity = taskInfo.baseActivity;
		}
	}
	return runningTaskInfos;
}
 
开发者ID:codehz,项目名称:container,代码行数:14,代码来源:GetTasks.java

示例15: getTopRunningTask

import android.app.ActivityManager; //导入方法依赖的package包/类
/**
 * 获取指定程序信息
 */
public static ActivityManager.RunningTaskInfo getTopRunningTask(Context context) {
    try {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        // 得到当前正在运行的任务栈
        List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1);
        // 得到前台显示的任务栈
        ActivityManager.RunningTaskInfo runningTaskInfo = runningTasks.get(0);
        return runningTaskInfo;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:jqjm,项目名称:Liteframework,代码行数:17,代码来源:PackageUtil.java


注:本文中的android.app.ActivityManager.RunningTaskInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。