當前位置: 首頁>>代碼示例>>Java>>正文


Java RunningTaskInfo類代碼示例

本文整理匯總了Java中android.app.ActivityManager.RunningTaskInfo的典型用法代碼示例。如果您正苦於以下問題:Java RunningTaskInfo類的具體用法?Java RunningTaskInfo怎麽用?Java RunningTaskInfo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RunningTaskInfo類屬於android.app.ActivityManager包,在下文中一共展示了RunningTaskInfo類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isAppOnForeground

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
@SuppressLint({"NewApi"})
public static boolean isAppOnForeground(Context mContext) {
    ActivityManager activityManager = (ActivityManager) mContext.getSystemService("activity");
    String packageName = mContext.getPackageName();
    LogInfo.log("PushReceiver", "packageName =" + packageName);
    List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
    if (appProcesses == null) {
        LogInfo.log("PushReceiver", "------appProcesses == null-----");
        return false;
    }
    for (RunningAppProcessInfo appProcess : appProcesses) {
        LogInfo.log("PushReceiver", "------appProcess.processName =" + appProcess.processName);
        if (appProcess.processName.equals(packageName) && appProcess.importance == 100) {
            for (RunningTaskInfo rti : activityManager.getRunningTasks(100)) {
                if (!(rti == null || rti.baseActivity == null || mContext.getPackageName() == null || !mContext.getPackageName().equals(rti.baseActivity.getPackageName()) || VERSION.SDK_INT < 11)) {
                    activityManager.moveTaskToFront(rti.id, 1);
                }
            }
            return true;
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:24,代碼來源:PushNotificationReceiver.java

示例2: isAppOnForeground

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * 	判斷當前應用是否是頂棧
 * @param context
 * @return
 */
public static boolean isAppOnForeground(Context context){
	PackageInfo info = null;
	try{
	info=context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
	String curPackage=info.packageName;
	ActivityManager mActivityManager = ((ActivityManager) context.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE));
	List<RunningTaskInfo> tasksInfo = mActivityManager.getRunningTasks(1);
	if(tasksInfo!=null && tasksInfo.size()>0){
		if (!TextUtils.isEmpty(curPackage) && curPackage.equals(tasksInfo.get(0).topActivity.getPackageName())) {
			/**當前應用是頂棧*/
			return true;
		} 
		
	}
	}catch(Exception ex){
		LogUtils.e(ex.toString());
	}
	return false;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:25,代碼來源:AppUtils.java

示例3: IsBaseActivityRunningPreAPI23

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
public boolean IsBaseActivityRunningPreAPI23() {
    ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);

    if (activityManager == null) {
        Logger.getInstance().Error(TAG, "ActivityManager is null!");
        return false;
    }

    List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

    for (RunningTaskInfo task : tasks) {
        if (_context.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName())) {
            return true;
        }
    }

    return false;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:19,代碼來源:AndroidSystemController.java

示例4: isTopActivity

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 *
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 * stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || packageName == null || packageName.length() == 0) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (tasksInfo == null || tasksInfo.size() == 0) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:lizhangqu,項目名稱:CorePatch,代碼行數:30,代碼來源:PackageUtils.java

示例5: b

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
public final void b() {
    try {
        ActivityManager activityManager = (ActivityManager) getSystemService(z[19]);
        ComponentName componentName = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).baseActivity;
        ComponentName componentName2 = ((RunningTaskInfo) activityManager.getRunningTasks(1).get(0)).topActivity;
        new StringBuilder(z[17]).append(componentName.toString());
        z.b();
        new StringBuilder(z[18]).append(componentName2.toString());
        z.b();
        if (!(componentName == null || componentName2 == null || !componentName2.toString().equals(componentName.toString()))) {
            c();
        }
    } catch (Exception e) {
        c();
    }
    finish();
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:PushActivity.java

示例6: getAppTopActivityName

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * <一句話功能簡述> 獲取最上麵活躍的Activity
 * 
 * @Description<功能詳細描述>
 * 
 * @param context
 * @return
 * @LastModifiedDate:2015-9-6
 * @author rqj
 * @EditHistory:<修改內容><修改人>
 */
public static String getAppTopActivityName(Context context) {
	String packageName = context.getPackageName();
	ActivityManager activityManager = (ActivityManager) context
			.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningTaskInfo> runningTaskInfos = activityManager
			.getRunningTasks(256);
	for (RunningTaskInfo info : runningTaskInfos) {
		System.out.println(info.topActivity.getPackageName() + "   "
				+ info.topActivity.getClassName());
		if (packageName != null
				&& info.topActivity.getPackageName() != null
				&& packageName.equals(info.topActivity.getPackageName())) {
			return info.topActivity.getClassName();
		}
	}
	return null;
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:29,代碼來源:AppPackageUtil.java

示例7: isBackground

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * <一句話功能簡述> 判斷Activity是否已經退到後台
 * 
 * @Description<功能詳細描述>
 * 
 * @param context
 * @return
 * @LastModifiedDate:2015-9-6
 * @author rqj
 * @EditHistory:<修改內容><修改人>
 */
public static boolean isBackground(Context context) {
	// 判斷前提,已經不在前台
	String packageName = context.getPackageName();
	ActivityManager activityManager = (ActivityManager) context
			.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningTaskInfo> runningTaskInfos = activityManager
			.getRunningTasks(100);
	for (RunningTaskInfo info : runningTaskInfos) {
		if (packageName != null
				&& info.topActivity.getPackageName() != null
				&& packageName.equals(info.topActivity.getPackageName())) {
			return true;
		}
	}
	return false;
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:28,代碼來源:AppPackageUtil.java

示例8: getTopTaskPackageName

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
public String getTopTaskPackageName() {
    boolean checkPermission;
    try {
        checkPermission = checkPermission("android.permission.GET_TASKS");
    } catch (Throwable th) {
        Ln.w(th);
        checkPermission = false;
    }
    if (checkPermission) {
        try {
            ActivityManager activityManager = (ActivityManager) getSystemService(ModelName
                    .ACTIVITY);
            return activityManager == null ? null : ((RunningTaskInfo) activityManager
                    .getRunningTasks(1).get(0)).topActivity.getPackageName();
        } catch (Throwable th2) {
            Ln.w(th2);
        }
    }
    return null;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:DeviceHelper.java

示例9: isAppExit

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
private boolean isAppExit() {
    if (MWConfiguration.getContext() == null) {
        return true;
    }
    String packageName = MWConfiguration.getContext().getPackageName();
    if (o.a(MWConfiguration.getContext(), "android.permission.GET_TASKS")) {
        ActivityManager activityManager = (ActivityManager) MWConfiguration.getContext()
                .getSystemService(ModelName.ACTIVITY);
        if (activityManager != null && l.b(activityManager.getRunningTasks(1)) &&
                activityManager.getRunningTasks(1).get(0) != null && ((RunningTaskInfo)
                activityManager.getRunningTasks(1).get(0)).topActivity != null) {
            return !packageName.equals(((RunningTaskInfo) activityManager.getRunningTasks(1)
                    .get(0)).topActivity.getPackageName());
        } else if (isAppOnForeground()) {
            return false;
        } else {
            return true;
        }
    } else if (isAppOnForeground()) {
        return false;
    } else {
        return true;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:25,代碼來源:TrackAgent.java

示例10: discoverStartedActivityPid

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
private void discoverStartedActivityPid() {

		ActivityManager activityManager = (ActivityManager) getContext()
				.getSystemService(Context.ACTIVITY_SERVICE);
		List<RunningTaskInfo> services = activityManager
				.getRunningTasks(Integer.MAX_VALUE);
		List<RunningAppProcessInfo> apps = activityManager
				.getRunningAppProcesses();
		String packageName = services.get(0).topActivity.getPackageName(); // fist
																			// Task
																			// is
																			// the
																			// last
																			// started
																			// task
		for (int i = 0; i < apps.size(); i++) {
			if (apps.get(i).processName.equals(packageName)) {
				appPid = apps.get(i).pid;
				Log.d(getClass().getName(),
						"Found activity process: " + apps.get(i).processName
								+ " PID: " + appPid);
			}

		}
	}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:26,代碼來源:MultiContentPlayer.java

示例11: discoverMusicActivityPid

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
private void discoverMusicActivityPid() {
	
	ActivityManager activityManager = (ActivityManager) getContext()
			.getSystemService(Context.ACTIVITY_SERVICE);
	List<RunningTaskInfo> services = activityManager
			.getRunningTasks(Integer.MAX_VALUE);
	List<RunningAppProcessInfo> apps = activityManager.getRunningAppProcesses();
	String packageName = services.get(0).topActivity.getPackageName(); //fist Task is the last started task		
	for (int i = 0; i < apps.size(); i++) {
	    if(apps.get(i).processName .equals(packageName)){
	    	musicAppPid = apps.get(i).pid;
	    	Log.d(getClass().getName(), "Found music activity process: " + apps.get(i).processName + " PID: " + musicAppPid);
	    }
		
	}
}
 
開發者ID:theopenbit,項目名稱:yaacc-code,代碼行數:17,代碼來源:LocalThirdPartieMusicPlayer.java

示例12: isTopActivity

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 * 
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of
 *         stack
 */
public static Boolean isTopActivity(Context context, String packageName) {
    if (context == null || StringUtils.isEmpty(packageName)) {
        return null;
    }

    ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
    if (ListUtils.isEmpty(tasksInfo)) {
        return null;
    }
    try {
        return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:macyuan,項目名稱:TAG,代碼行數:30,代碼來源:PackageUtils.java

示例13: getCurrentForegroundApp

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
private String getCurrentForegroundApp() {
	String currentForegroundApp = null;
	try {
		ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		// The first in the list of RunningTasks is always the foreground
		// task.
		RunningTaskInfo foregroundTaskInfo = am.getRunningTasks(1).get(0);
		String foregroundTaskPackageName = foregroundTaskInfo.topActivity.getPackageName();
		Log.d(SmartConstants.APP_NAME, "PushMessageNotifier->foregroundTaskPackageName:" + foregroundTaskPackageName);
		currentForegroundApp = foregroundTaskPackageName;
		PackageManager pm = context.getPackageManager();
		PackageInfo foregroundAppPackageInfo;

		foregroundAppPackageInfo = pm.getPackageInfo(foregroundTaskPackageName, 0);

		String foregroundTaskAppName = foregroundAppPackageInfo.applicationInfo.loadLabel(pm).toString();
		Log.d(SmartConstants.APP_NAME, "PushMessageNotifier->getCurrentForegroundApp:" + foregroundTaskAppName + ",app package name:" + context.getPackageName());
	} catch (NameNotFoundException e) {
		// TODO handle this exception
	}
	return currentForegroundApp;
}
 
開發者ID:appez,項目名稱:appez-android,代碼行數:23,代碼來源:PushNotificationUtility.java

示例14: isTopActivity

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
/**
 * whether the app whost package's name is packageName is on the top of the stack
 * <ul>
 * <strong>Attentions:</strong>
 * <li>You should add <strong>android.permission.GET_TASKS</strong> in manifest</li>
 * </ul>
 * 
 * @param context
 * @param packageName
 * @return if params error or task stack is null, return null, otherwise retun whether the app is on the top of stack
 */
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<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1);
	if (tasksInfo == null || tasksInfo.size() == 0) {
		return null;
	}
	try {
		return packageName.equals(tasksInfo.get(0).topActivity.getPackageName());
	} catch (Exception e) {
		e.printStackTrace();
		return false;
	}
}
 
開發者ID:imknown,項目名稱:IMKBaseFrameworkLibrary,代碼行數:29,代碼來源:PackageUtils.java

示例15: onPause

import android.app.ActivityManager.RunningTaskInfo; //導入依賴的package包/類
protected void onPause() {
 if (this.isFinishing()){ //basically BACK was pressed from this activity
 //mp.stop();
  }
else{

}
 Context context = getApplicationContext();
 ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
 List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
 if (!taskInfo.isEmpty()) {
 ComponentName topActivity = taskInfo.get(0).topActivity; 
 if (!topActivity.getPackageName().equals(context.getPackageName())) {
 //mp.stop();

}
}
   super.onPause();

 }
 
開發者ID:hamdiburakdilek,項目名稱:Calculable,代碼行數:21,代碼來源:Splash.java


注:本文中的android.app.ActivityManager.RunningTaskInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。