本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}