本文整理匯總了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;
}