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