当前位置: 首页>>代码示例>>Java>>正文


Java ActivityManager类代码示例

本文整理汇总了Java中android.app.ActivityManager的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager类的具体用法?Java ActivityManager怎么用?Java ActivityManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ActivityManager类属于android.app包,在下文中一共展示了ActivityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurProcessName

import android.app.ActivityManager; //导入依赖的package包/类
public static String getCurProcessName(Context context) {

        int pid = android.os.Process.myPid();

        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);

        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager
                .getRunningAppProcesses()) {

            if (appProcess.pid == pid) {
                return appProcess.processName;
            }
        }
        return null;
    }
 
开发者ID:lo625090140,项目名称:lqrwechatrongcloud,代码行数:17,代码来源:MyApp.java

示例2: isNamedProcess

import android.app.ActivityManager; //导入依赖的package包/类
/**
 * whether this process is named with processName
 * 
 * @param context
 * @param processName
 * @return <ul>
 *         return whether this process is named with processName
 *         <li>if context is null, return false</li>
 *         <li>if {@link ActivityManager#getRunningAppProcesses()} is null, return false</li>
 *         <li>if one process of {@link ActivityManager#getRunningAppProcesses()} is equal to processName, return
 *         true, otherwise return false</li>
 *         </ul>
 */
public static boolean isNamedProcess(Context context, String processName) {
    if (context == null) {
        return false;
    }

    int pid = android.os.Process.myPid();
    ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
    if (ListUtils.isEmpty(processInfoList)) {
        return false;
    }

    for (RunningAppProcessInfo processInfo : processInfoList) {
        if (processInfo != null && processInfo.pid == pid
                && ObjectUtils.isEquals(processName, processInfo.processName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:harrylefit,项目名称:eazycore,代码行数:34,代码来源:AppUtils.java

示例3: excludeFromTaskList

import android.app.ActivityManager; //导入依赖的package包/类
/**
 * Exclude the app from the recent tasks list.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void excludeFromTaskList() {
    ActivityManager am = (ActivityManager) getActivity()
            .getSystemService(Context.ACTIVITY_SERVICE);

    if (am == null || Build.VERSION.SDK_INT < 21)
        return;

    List<AppTask> tasks = am.getAppTasks();

    if (tasks == null || tasks.isEmpty())
        return;

    tasks.get(0).setExcludeFromRecents(true);
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:19,代码来源:BackgroundExt.java

示例4: isLowMemoryDevice

import android.app.ActivityManager; //导入依赖的package包/类
private static boolean isLowMemoryDevice(ActivityManager activityManager) {
  // Explicitly check with an if statement, on some devices both parts of boolean expressions
  // can be evaluated even if we'd normally expect a short circuit.
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    return activityManager.isLowRamDevice();
  } else {
    return false;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:MemorySizeCalculator.java

示例5: getAllBackgroundProcesses

import android.app.ActivityManager; //导入依赖的package包/类
/**
 * 获取后台服务进程
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>}</p>
 *
 * @return 后台服务进程
 */
public static Set<String> getAllBackgroundProcesses() {
    ActivityManager am = (ActivityManager) Utils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningAppProcessInfo> infos = am.getRunningAppProcesses();
    Set<String> set = new HashSet<>();
    for (ActivityManager.RunningAppProcessInfo info : infos) {
        Collections.addAll(set, info.pkgList);
    }
    return set;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:16,代码来源:ProcessUtils.java

示例6: getInstance

import android.app.ActivityManager; //导入依赖的package包/类
public synchronized static ContactPictureCache getInstance(Context context) {
    if (sInstance == null) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        sMemClass = activityManager.getMemoryClass();
        sInstance = new ContactPictureCache();
    }
    return sInstance;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:9,代码来源:ContactPictureCache.java

示例7: isLowMemory

import android.app.ActivityManager; //导入依赖的package包/类
@TargetApi(VERSION_CODES.KITKAT)
public static boolean isLowMemory(Context context) {
  ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

  return (VERSION.SDK_INT >= VERSION_CODES.KITKAT && activityManager.isLowRamDevice()) ||
         activityManager.getMemoryClass() <= 64;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:8,代码来源:Util.java

示例8: getAppName

import android.app.ActivityManager; //导入依赖的package包/类
private String getAppName(int pID) {
    String processName = null;
    ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return null;
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:19,代码来源:Application.java

示例9: isServerRunning

import android.app.ActivityManager; //导入依赖的package包/类
public static boolean isServerRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> runningServices = manager.getRunningServices(Integer.MAX_VALUE);
    String ftpServiceClassName = ConnectionsService.class.getName();
    for (ActivityManager.RunningServiceInfo service : runningServices) {
        String currentClassName = service.service.getClassName();
        if (ftpServiceClassName.equals(currentClassName)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:13,代码来源:ConnectionUtils.java

示例10: init

import android.app.ActivityManager; //导入依赖的package包/类
void init(OpenGLEngine engine) {
	// Check if the system supports OpenGL ES 2.0.
	final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
	final ConfigurationInfo configurationInfo = activityManager
			.getDeviceConfigurationInfo();
	final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

	if (supportsEs2) {
		// Request an OpenGL ES 2.0 compatible context.
		engine.setEGLContextClientVersion(2);

		// Set the renderer to our user-defined renderer.
		engine.setRenderer(getNewRenderer());
	} else {
		// This is where you could create an OpenGL ES 1.x compatible
		// renderer if you wanted to support both ES 1 and ES 2.
		return;
	}
}
 
开发者ID:biezhihua,项目名称:Android_OpenGL_Demo,代码行数:20,代码来源:OpenGLES2WallpaperService.java

示例11: queryRunningService

import android.app.ActivityManager; //导入依赖的package包/类
private void queryRunningService() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceInfoList =
            manager.getRunningServices(Integer.MAX_VALUE);

    for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfoList) {
        Log.d(TAG, "queryRunningService: \n"
                + "process:"
                + serviceInfo.process
                + "\n---service:"
                + serviceInfo.service.flattenToString()
                + "\n---pid:"
                + serviceInfo.pid
                + "\n---uid:"
                + serviceInfo.uid
                + "\n---clientPackage:"
                + serviceInfo.clientPackage
                + "\n---lastActivityTime:"
                + serviceInfo.lastActivityTime);
    }
}
 
开发者ID:jiangkang,项目名称:KTools,代码行数:22,代码来源:DeviceActivity.java

示例12: isServiceRunning

import android.app.ActivityManager; //导入依赖的package包/类
/**
 * Check if a service is running
 *
 * @param context      The context
 * @param serviceClass The class of the service to check
 * @return true if it is, false if not.
 */
public static boolean isServiceRunning(Context context, Class<?> serviceClass) {
    if(context == null){
        throw new IllegalArgumentException("Context cannot be null");
    }

    if(serviceClass == null){
        throw new IllegalArgumentException("Class cannot be null");
    }

    ActivityManager manager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);

    if(manager == null){
        return false;
    }

    for (ActivityManager.RunningServiceInfo service : manager
            .getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:Mindera,项目名称:skeletoid,代码行数:32,代码来源:AndroidUtils.java

示例13: isForeground

import android.app.ActivityManager; //导入依赖的package包/类
private boolean isForeground(Context context) {
    try {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();
        if (runningAppProcesses != null) {
            int myPid = android.os.Process.myPid();
            for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
                if (runningAppProcessInfo.pid == myPid) {
                    return runningAppProcessInfo.importance <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "e:", e);
    }
    return false;
}
 
开发者ID:isuperqiang,项目名称:AndroidKeepLivePractice,代码行数:18,代码来源:CheckTopTask.java

示例14: tearDown

import android.app.ActivityManager; //导入依赖的package包/类
@Override
protected void tearDown() throws Exception {
    int counter = 10;
    if (testRealm != null) {
        testRealm.close();
    }

    getContext().unbindService(serviceConnection);
    remoteMessenger = null;

    // Kills the remote process.
    ActivityManager.RunningAppProcessInfo info = getRemoteProcessInfo();
    if (info != null) {
        android.os.Process.killProcess(info.pid);
    }
    while (getRemoteProcessInfo() != null) {
        if (counter == 0) {
            assertTrue("The remote service process is still alive.", false);
        }
        Thread.sleep(300);
        counter--;
    }
    super.tearDown();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RealmInterprocessTest.java

示例15: 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:rctl,项目名称:CryptoVoice,代码行数:25,代码来源:Main.java


注:本文中的android.app.ActivityManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。