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