當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。