本文整理汇总了Java中android.app.ActivityManager.RunningAppProcessInfo方法的典型用法代码示例。如果您正苦于以下问题:Java ActivityManager.RunningAppProcessInfo方法的具体用法?Java ActivityManager.RunningAppProcessInfo怎么用?Java ActivityManager.RunningAppProcessInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.ActivityManager
的用法示例。
在下文中一共展示了ActivityManager.RunningAppProcessInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.app.ActivityManager; //导入方法依赖的package包/类
@Override
public void onCreate() {
mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
// catch up in case we crashed but other processes are still running
List<ActivityManager.RunningServiceInfo> svcs = mAm.getRunningServices(256);
for (ActivityManager.RunningServiceInfo svc : svcs) {
if (svc.service.getPackageName().equals(getPackageName())) {
Log.v(TAG, "discovered running service: " + svc.process + " (" + svc.pid + ")");
startTrackingProcess(svc.pid, svc.process,
System.currentTimeMillis() - (SystemClock.elapsedRealtime() - svc.activeSince));
}
}
List<ActivityManager.RunningAppProcessInfo> procs = mAm.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo proc : procs) {
final String pname = proc.processName;
if (pname.startsWith(getPackageName())) {
Log.v(TAG, "discovered other running process: " + pname + " (" + proc.pid + ")");
startTrackingProcess(proc.pid, pname, System.currentTimeMillis());
}
}
}
示例2: getProcessName
import android.app.ActivityManager; //导入方法依赖的package包/类
private String getProcessName(Context context) {
try {
int pid = android.os.Process.myPid();
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningProcess = am.getRunningAppProcesses();
StringBuilder stringBuilder = new StringBuilder();
int size = runningProcess.size();
for (int i = 0; i < size; i++) {
ActivityManager.RunningAppProcessInfo info = runningProcess.get(i);
if (info.pid == pid) {
stringBuilder.append(info.processName);
}
}
return stringBuilder.toString();
} catch (Exception e) {
}
return "";
}
示例3: 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;
}
示例4: 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> info = am.getRunningAppProcesses();
Set<String> set = new HashSet<>();
for (ActivityManager.RunningAppProcessInfo aInfo : info) {
Collections.addAll(set, aInfo.pkgList);
}
return set;
}
示例5: isAppInForeground
import android.app.ActivityManager; //导入方法依赖的package包/类
private static boolean isAppInForeground (Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
final String packageName = context.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
}
示例6: getProcessName
import android.app.ActivityManager; //导入方法依赖的package包/类
private String getProcessName(int pid) {
for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
if (info.pid == pid) {
return info.processName;
}
}
return null;
}
示例7: getRunningAppProcessesHandleException
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* Android5.0及以上版本,{@link ActivityManager#getRunningAppProcesses()}只能读取到自己的进程信息;
*
* @param activityManager
* @return
*/
private static List<ActivityManager.RunningAppProcessInfo> getRunningAppProcessesHandleException(ActivityManager activityManager) {
List<ActivityManager.RunningAppProcessInfo> processInfos = null;
if (activityManager != null) {
try {
processInfos = activityManager.getRunningAppProcesses();
} catch (RuntimeException e) {
if (Build.VERSION.SDK_INT >= AndroidVersionCodes.N) { // Android7.0
// lge LG-H860 7.0(24)、motorola Moto G 7.1(25)、Xiaomi Mi-4c 7.0(24)、Sony F8132 7.0(24)
// java.lang.RuntimeException: An error occurred while executing doInBackground()
// at android.os.AsyncTask$3.done(AsyncTask.java:318)
// at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
// at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
// at java.util.concurrent.FutureTask.run(FutureTask.java:242)
// at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
// at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
// at java.lang.Thread.run(Thread.java:761)
// Caused by: java.lang.RuntimeException: android.os.DeadSystemException
// at android.app.ActivityManager.getRunningAppProcesses(ActivityManager.java:3024)
// at com.qihoo.utils.AndroidUtilsCompat.getTopPkgNameByActivityManager(AppStore:320)
// at com.qihoo.utils.AndroidUtilsCompat.getTopPkgName(AppStore:298)
// at com.qihoo.appstore.utils.InjectActivityThreadH$StatRunnable.run(AppStore:75)
// at com.qihoo.utils.thread.ThreadUtils$1.doInBackground(AppStore:44)
// at com.qihoo.utils.thread.ThreadUtils$1.doInBackground(AppStore:38)
// at android.os.AsyncTask$2.call(AsyncTask.java:304)
// at java.util.concurrent.FutureTask.run(FutureTask.java:237)
// ... 3 more
// Caused by: android.os.DeadSystemException
// ... 11 more
} else {
throw e;
}
}
}
return processInfos;
}
示例8: getCurrentProcessName
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 获取当前进程名
*/
public static String getCurrentProcessName() {
int pid = android.os.Process.myPid();
String processName = "";
ActivityManager manager = (ActivityManager) UtilManager.getContext().getSystemService(Context.ACTIVITY_SERVICE);
if (manager != null) {
for (ActivityManager.RunningAppProcessInfo process : manager.getRunningAppProcesses()) {
if (process.pid == pid) {
processName = process.processName;
}
}
}
return processName;
}
示例9: isBackgroundRunning
import android.app.ActivityManager; //导入方法依赖的package包/类
private boolean isBackgroundRunning(){
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
if (procInfos != null)
{
for (final ActivityManager.RunningAppProcessInfo processInfo : procInfos) {
if (processInfo.processName.equals("com.braunster.androidchatsdk.app")) {
Log.d(TAG, "From: " + processInfo.processName + " is working!!!!!!" );
return true;
}
}
}
return false;
}
示例10: getProcessName
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 获取进程名字
*
* @param cxt
* @param pid
* @return
*/
public static String getProcessName(Context cxt, int pid) {
ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
if (runningApps == null) {
return null;
}
for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
if (procInfo.pid == pid) {
return procInfo.processName;
}
}
return null;
}
示例11: isTop
import android.app.ActivityManager; //导入方法依赖的package包/类
public static boolean isTop(Context context) {
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.processName.equals(context.getPackageName())) {
return appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
}
}
return false;
}
示例12: getRemoteProcessInfo
import android.app.ActivityManager; //导入方法依赖的package包/类
private ActivityManager.RunningAppProcessInfo getRemoteProcessInfo() {
ActivityManager manager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processInfoList = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo info : processInfoList) {
if (info.processName.equals(getContext().getPackageName() + ":remote")) {
return info;
}
}
return null;
}
示例13: isMainProcess
import android.app.ActivityManager; //导入方法依赖的package包/类
public boolean isMainProcess() {
ActivityManager am = ((ActivityManager) getSystemService(Context.ACTIVITY_SERVICE));
List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
String mainProcessName = getPackageName();
int myPid = android.os.Process.myPid();
for (ActivityManager.RunningAppProcessInfo info : processInfos) {
if (info.pid == myPid && mainProcessName.equals(info.processName)) {
return true;
}
}
return false;
}
示例14: resetPackagerOtherProcess
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 重启当前包名下的其他进程
*
* @param context
*/
public static void resetPackagerOtherProcess(Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo ai : am.getRunningAppProcesses()) {
if (ai.uid == android.os.Process.myUid() && ai.pid != android.os.Process.myPid()) {
android.os.Process.killProcess(ai.pid);
}
}
}
示例15: getRunningAppProcessesNoThrows
import android.app.ActivityManager; //导入方法依赖的package包/类
/**
* 无需抛出异常而调用getRunningAppProcesses方法
* @param context context对象
* @return RunningAppProcessInfo列表
*/
public static List<ActivityManager.RunningAppProcessInfo> getRunningAppProcessesNoThrows(Context context) {
try {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
return am.getRunningAppProcesses();
} catch (Throwable e) {
// 可能AMS挂了,但最多返回空列表即可。毕竟不是很重要的流程
e.printStackTrace();
}
return null;
}