Java 类android.app.ActivityManager 实例源码

项目:lqrwechatrongcloud    文件:MyApp.java   
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;
    }
项目:eazycore    文件:AppUtils.java   
/**
 * 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;
}
项目:localcloud_fe    文件:BackgroundExt.java   
/**
 * 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);
}
项目:SmartChart    文件:Application.java   
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;
}
项目:Android_OpenGL_Demo    文件:OpenGLES2WallpaperService.java   
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;
    }
}
项目:KTools    文件:DeviceActivity.java   
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);
    }
}
项目:skeletoid    文件:AndroidUtils.java   
/**
 * 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;
}
项目:AndroidKeepLivePractice    文件:CheckTopTask.java   
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;
}
项目:GitHub    文件:RealmInterprocessTest.java   
@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();
}
项目:CryptoVoice    文件:Main.java   
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;
}
项目:NeiHanDuanZiTV    文件:AppManager.java   
/**
 * 退出应用程序
 */
public void appExit() {
    try {
        killAll();
        release();
        if (mActivityList != null)
            mActivityList = null;
        ActivityManager activityMgr =
                (ActivityManager) mApplication.getSystemService(Context.ACTIVITY_SERVICE);
        activityMgr.killBackgroundProcesses(mApplication.getPackageName());
        mApplication = null;
        activityMgr = null;
        System.exit(0);
        for (int i = 0; i < 100; i++) {
            System.gc();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:amap    文件:SystemUtils.java   
/**
 * 判断service是否正在运行
 *
 * @param mContext
 * @param className
 * @return
 */
public static boolean isServiceRunning(Context mContext, String className)
{

    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(200);

    if (!(serviceList.size() > 0))
    {
        return false;
    }


    for (int i = 0; i < serviceList.size(); i++)
    {
        if (serviceList.get(i).service.getClassName().equals(className) == true)
        {
            isRunning = true;
            break;
        }
    //  Log.d("Service:", "isServiceRunning: "+serviceList.get(i).service.getClassName());

    }
    return isRunning;
}
项目:KUtils    文件:AppManager.java   
/**
 * 退出应用程序
 *
 * @param context      上下文
 * @param isBackground 是否开开启后台运行
 */
public void AppExit(Context context, Boolean isBackground) {
    try {
        finishAllActivity();
        ActivityManager activityMgr = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        activityMgr.restartPackage(context.getPackageName());
    } catch (Exception e) {

    } finally {
        // 注意,如果您有后台程序运行,请不要支持此句子
        if (!isBackground) {
            System.exit(0);
        }
    }
}
项目:TestChat    文件:CommonUtils.java   
public static boolean isAppOnForeground(Context context) {
                ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
                List<ActivityManager.RunningAppProcessInfo> list = manager.getRunningAppProcesses();
                if (list == null) {
                        return false;
                }
                for (ActivityManager.RunningAppProcessInfo info :
                        list) {
                        if (info.processName.equals(context.getPackageName())) {
//                                BACKGROUND=400 EMPTY=500 FOREGROUND=100
//                                GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=20

                                if (info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                                        return true;
                                }
                        }
                }
                return false;
        }
项目:AppVisibilityDetector    文件:AppVisibilityDetector.java   
public static boolean checkIsMainProcess(Application app) {
    ActivityManager activityManager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses();
    if (null == runningAppProcessInfoList) {
        return false;
    }

    String currProcessName = null;
    int currPid = android.os.Process.myPid();
    //find the process name
    for (RunningAppProcessInfo processInfo : runningAppProcessInfoList) {
        if (null != processInfo && processInfo.pid == currPid) {
            currProcessName = processInfo.processName;
        }
    }

    //is current process the main process
    if (!TextUtils.equals(currProcessName, app.getPackageName())) {
        return false;
    }

    return true;
}
项目:VirtualHook    文件:VActivityManagerService.java   
@Override
public VParceledListSlice<ActivityManager.RunningServiceInfo> getServices(int maxNum, int flags, int userId) {
    synchronized (mHistory) {
        List<ActivityManager.RunningServiceInfo> services = new ArrayList<>(mHistory.size());
        for (ServiceRecord r : mHistory) {
            if (r.process.userId != userId) {
                continue;
            }
            ActivityManager.RunningServiceInfo info = new ActivityManager.RunningServiceInfo();
            info.uid = r.process.vuid;
            info.pid = r.process.pid;
            ProcessRecord processRecord = findProcessLocked(r.process.pid);
            if (processRecord != null) {
                info.process = processRecord.processName;
                info.clientPackage = processRecord.info.packageName;
            }
            info.activeSince = r.activeSince;
            info.lastActivityTime = r.lastActivityTime;
            info.clientCount = r.getClientCount();
            info.service = ComponentUtils.toComponentName(r.serviceInfo);
            info.started = r.startId > 0;
        }
        return new VParceledListSlice<>(services);
    }
}
项目:HLOLI    文件:AppManager.java   
/**
 * 退出应用程序
 *
 * @param context      上下文
 * @param isBackground 是否开开启后台运行
 */
public void AppExit(Context context, Boolean isBackground) {
    try {
        finishAllActivity();
        ActivityManager activityMgr = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        activityMgr.restartPackage(context.getPackageName());
    } catch (Exception e) {

    } finally {
        // 注意,如果您有后台程序运行,请不要支持此句子
        if (!isBackground) {
            System.exit(0);
        }
    }
}
项目:FriendBook    文件:SystemTool.java   
/**
 * 判断某个服务是否正在运行的方法
 *
 * @param mContext
 * @param serviceName
 *            是包名+服务的类名(例如:net.loonggg.testbackstage.TestService)
 * @return true代表正在运行,false代表服务没有正在运行
 */
public boolean isServiceWork(Context mContext, String serviceName) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager) mContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> myList = myAM.getRunningServices(40);
    if (myList.size() <= 0) {
        return false;
    }
    for (int i = 0; i < myList.size(); i++) {
        String mName = myList.get(i).service.getClassName().toString();
        if (mName.equals(serviceName)) {
            isWork = true;
            break;
        }
    }
    return isWork;
}
项目:PlayAndroid    文件:BaseActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //最近列表显示的缩略图的label,icon,top bar color
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityManager.TaskDescription taskDesc = new ActivityManager.TaskDescription(
                getTitle().toString(),
                BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round));
        setTaskDescription(taskDesc);
    }
    setContentView(initContentView());
    initStatusBar();
    initToolbar();
    init();
    initView();
    initData();
}
项目:AndelaTrackChallenge    文件:WelcomeActivity.java   
private void updateTaskDescription(int position) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable
                ? ((BitmapDrawable) iconDrawable).getBitmap()
                : null;
        int colorPrimary;
        if (position < slidesAdapter.getCount()) {
            colorPrimary = ContextCompat.getColor(this,
                    slidesAdapter.slides.get(position).backgroundColor);
        } else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);
        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
项目:stynico    文件:smali_layout_apktool.java   
private void b()
{

    mHandler.sendEmptyMessage(0x1);

    ActivityManager activityManager = (ActivityManager)smali_layout_apktool.this.getSystemService(ACTIVITY_SERVICE);

    if (processNamelist != null && processNamelist.size() > 0)
    {
        for (String processName : processNamelist)
        {
            activityManager.killBackgroundProcesses(processName);
        }
    }
    mHandler.sendEmptyMessageDelayed(0x2, 2000);
}
项目:stynico    文件:io_styTool.java   
/** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
super.onCreate(savedInstanceState);
setContentView(R.layout.io_root);
StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
ListView sa=(ListView)findViewById(R.id.mainListView1);
try
{
    ActivityManager qw=(ActivityManager)io_styTool.this.getSystemService(ACTIVITY_SERVICE);
    ArrayList<String> ary=new ArrayList<String>();
    List<ActivityManager.RunningAppProcessInfo> act=qw.getRunningAppProcesses();
    int i=1;
    for (ActivityManager.RunningAppProcessInfo a:act)
    {
    ary.add((i++) + ": " + a.processName + "\n" + " id " + a.pid + " uid " + a.uid);
    }
    ArrayAdapter shi=new ArrayAdapter<String>(io_styTool.this, android.R.layout.simple_list_item_1, ary);
    sa.setAdapter(shi);
}
catch (Exception e)
{
    Toast.makeText(io_styTool.this, e.toString(), Toast.LENGTH_LONG).show();
}
   }
项目:FanChat    文件:EaseCommonUtils.java   
/**
 * get top activity
 * @param context
 * @return
 */
public static String getTopActivity(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

    if (runningTaskInfos != null)
        return runningTaskInfos.get(0).topActivity.getClassName();
    else
        return "";
}
项目:lineagex86    文件:NotificationStation.java   
@Override
public void onAttach(Activity activity) {
    logd("onAttach(%s)", activity.getClass().getSimpleName());
    super.onAttach(activity);
    mContext = activity;
    mPm = mContext.getPackageManager();
    mNoMan = INotificationManager.Stub.asInterface(
            ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    try {
        mListener.registerAsSystemService(mContext, new ComponentName(mContext.getPackageName(),
                this.getClass().getCanonicalName()), ActivityManager.getCurrentUser());
    } catch (RemoteException e) {
        Log.e(TAG, "Cannot register listener", e);
    }
}
项目:lineagex86    文件:NotificationStation.java   
private List<HistoricalNotificationInfo> loadNotifications() {
    final int currentUserId = ActivityManager.getCurrentUser();
    try {
        StatusBarNotification[] active = mNoMan.getActiveNotifications(
                mContext.getPackageName());
        StatusBarNotification[] dismissed = mNoMan.getHistoricalNotifications(
                mContext.getPackageName(), 50);

        List<HistoricalNotificationInfo> list
                = new ArrayList<HistoricalNotificationInfo>(active.length + dismissed.length);

        for (StatusBarNotification[] resultset
                : new StatusBarNotification[][] { active, dismissed }) {
            for (StatusBarNotification sbn : resultset) {
                final HistoricalNotificationInfo info = new HistoricalNotificationInfo();
                info.pkg = sbn.getPackageName();
                info.user = sbn.getUserId();
                info.icon = loadIconDrawable(info.pkg, info.user, sbn.getNotification().icon);
                info.pkgicon = loadPackageIconDrawable(info.pkg, info.user);
                info.pkgname = loadPackageName(info.pkg);
                if (sbn.getNotification().extras != null) {
                    info.title = sbn.getNotification().extras.getString(
                            Notification.EXTRA_TITLE);
                    if (info.title == null || "".equals(info.title)) {
                        info.title = sbn.getNotification().extras.getString(
                                Notification.EXTRA_TEXT);
                    }
                }
                if (info.title == null || "".equals(info.title)) {
                    info.title = sbn.getNotification().tickerText;
                }
                // still nothing? come on, give us something!
                if (info.title == null || "".equals(info.title)) {
                    info.title = info.pkgname;
                }
                info.timestamp = sbn.getPostTime();
                info.priority = sbn.getNotification().priority;
                logd("   [%d] %s: %s", info.timestamp, info.pkg, info.title);

                info.active = (resultset == active);

                if (info.user == UserHandle.USER_ALL
                        || info.user == currentUserId) {
                    list.add(info);
                }
            }
        }

        return list;
    } catch (RemoteException e) {
        Log.e(TAG, "Cannot load Notifications: ", e);
    }
    return null;
}
项目:exciting-app    文件:CommonUtil.java   
public static boolean isBackground(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())) {
            /*
            BACKGROUND=400 EMPTY=500 FOREGROUND=100
            GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=200
             */
            Log.i(context.getPackageName(), "此appimportace ="
                    + appProcess.importance
                    + ",context.getClass().getName()="
                    + context.getClass().getName());
            if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                Log.i(context.getPackageName(), "处于后台"
                        + appProcess.processName);
                return true;
            } else {
                Log.i(context.getPackageName(), "处于前台"
                        + appProcess.processName);
                return false;
            }
        }
    }
    return false;
}
项目:Excuser    文件:Utils.java   
public static boolean isMyServiceRunning(Context context, Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
项目:VirtualHook    文件:MethodProxies.java   
@Override
public Object call(Object who, Method method, Object... args) throws Throwable {
    ActivityManager.TaskDescription td = (ActivityManager.TaskDescription) args[1];
    String label = td.getLabel();
    Bitmap icon = td.getIcon();

    // If the activity label/icon isn't specified, the application's label/icon is shown instead
    // Android usually does that for us, but in this case we want info about the contained app, not VIrtualApp itself
    if (label == null || icon == null) {
        Application app = VClientImpl.get().getCurrentApplication();
        if (app != null) {
            try {
                if (label == null) {
                    label = app.getApplicationInfo().loadLabel(app.getPackageManager()).toString();
                }
                if (icon == null) {
                    Drawable drawable = app.getApplicationInfo().loadIcon(app.getPackageManager());
                    if (drawable != null) {
                        icon = DrawableUtils.drawableToBitMap(drawable);
                    }
                }
                td = new ActivityManager.TaskDescription(label, icon, td.getPrimaryColor());
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    TaskDescriptionDelegate descriptionDelegate = VirtualCore.get().getTaskDescriptionDelegate();
    if (descriptionDelegate != null) {
        td = descriptionDelegate.getTaskDescription(td);
    }

    args[1] = td;
    return method.invoke(who, args);
}
项目:eazycore    文件:AppUtils.java   
/**
 * whether application is in background
 * <ul>
 * <li>need use permission android.permission.GET_TASKS in Manifest.xml</li>
 * </ul>
 * 
 * @param context
 * @return if application is in background return true, otherwise return false
 */
public static boolean isApplicationInBackground(Context context) {
    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> taskList = am.getRunningTasks(1);
    if (taskList != null && !taskList.isEmpty()) {
        ComponentName topActivity = taskList.get(0).topActivity;
        if (topActivity != null && !topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }
    }
    return false;
}
项目:TPlayer    文件:VirtualCore.java   
public boolean isEngineLaunched() {
    String engineProcessName = getEngineProcessName();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
        if (info.processName.endsWith(engineProcessName)) {
            return true;
        }
    }
    return false;
}
项目:TPlayer    文件:VActivityManagerService.java   
private String getProcessName(int pid) {
    for (ActivityManager.RunningAppProcessInfo info : am.getRunningAppProcesses()) {
        if (info.pid == pid) {
            return info.processName;
        }
    }
    return null;
}
项目:SmartChart    文件:CommonUtils.java   
public static boolean isSingleActivity(Context var0) {
    ActivityManager var1 = (ActivityManager) var0.getSystemService("activity_message");
    List var2 = null;

    try {
        var2 = var1.getRunningTasks(1);
    } catch (SecurityException var4) {
        var4.printStackTrace();
    }

    return var2 != null && var2.size() >= 1 ? ((ActivityManager.RunningTaskInfo) var2.get(0)).numRunning == 1 : false;
}
项目:EmulatorDetect    文件:EmulatorDetectorService.java   
public String getEmulatorName(Context context) {
    String sEmulatorName = null;
    final PackageManager packageManager = context.getPackageManager();
    List<ApplicationInfo> packages = packageManager
            .getInstalledApplications(PackageManager.GET_META_DATA);
    for (ApplicationInfo packageInfo : packages) {
        String packageName = packageInfo.packageName;
        if (packageName.startsWith("com.vphone.") || packageName.startsWith("com.bignox.")) {
            sEmulatorName = context.getString(R.string.emulator_name_yeshen);
        } else if (packageName.startsWith("me.haima.")) {
            sEmulatorName = context.getString(R.string.emulator_name_haimawan);
        } else if (packageName.startsWith("com.bluestacks.")) {
            sEmulatorName = context.getString(R.string.emulator_name_bluestacks);
        } else if (packageName.startsWith("cn.itools.")&&(Build.PRODUCT.startsWith("iToolsAVM")||Build.MANUFACTURER.startsWith("iToolsAVM")||Build.DEVICE.startsWith("iToolsAVM")||Build.MODEL.startsWith("iToolsAVM")||Build.BRAND.startsWith("generic")||Build.HARDWARE.startsWith("vbox86"))) {
            sEmulatorName = context.getString(R.string.emulator_name_itools);
        } else if (packageName.startsWith("com.kop.") || packageName.startsWith("com.kaopu.")) {
            sEmulatorName = context.getString(R.string.emulator_name_tiantian);
        } else if (packageName.startsWith("com.microvirt.")) {
            sEmulatorName = context.getString(R.string.emulator_name_xiaoyao);
        } else if (packageName.equals("com.google.android.launcher.layouts.genymotion")) {
            sEmulatorName = getString(R.string.emulator_name_genymotion);
        }
    }
    if (sEmulatorName == null) {
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> serviceInfos = manager.getRunningServices(30);
        for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfos) {
            String serviceName = serviceInfo.service.getClassName();
            if (serviceName.startsWith("com.bluestacks.")) {
                sEmulatorName = context.getString(R.string.emulator_name_bluestacks);
            }
        }
    }
    if (sEmulatorName == null && Build.PRODUCT.startsWith("sdk_google")) {
        sEmulatorName = context.getString(R.string.emulator_name_android);
    }
    return sEmulatorName == null ? "" : sEmulatorName;
}
项目:XinFramework    文件:SysUtils.java   
public static String getCurProcessName(Context ctx) {
    int pid = android.os.Process.myPid();
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    if (activityManager == null || activityManager.getRunningAppProcesses() == null) {
        return null;
    }
    for (ActivityManager.RunningAppProcessInfo processInfo : activityManager.getRunningAppProcesses()) {
        if (processInfo.pid == pid) {
            return processInfo.processName;
        }
    }
    return null;
}
项目:GitHub    文件:MemorySizeCalculator.java   
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;
  }
}
项目:RLibrary    文件:ProcessUtils.java   
/**
 * 获取后台服务进程
 * <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;
}
项目:SOS-The-Healthcare-Companion    文件:ContactPictureCache.java   
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;
}
项目:PeSanKita-android    文件:Util.java   
@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;
}
项目:simple-share-android    文件:ConnectionUtils.java   
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;
}
项目:GitHub    文件:MainActivity.java   
@Override
protected void onDestroy() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (CacheService.class.getName().equals(service.service.getClassName())) {
            stopService(new Intent(this, CacheService.class));
        }
    }
    super.onDestroy();
}