package com.wasu.cs.utils;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/**
 * @Description:
 * @Author: Danxingxi
 * @CreateDate: 2016/10/8 14:44
 */
public class DeviceUtils {

    /**
     * 获取进程name
     * @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;
    }
}
