Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;

import android.content.Context;

import java.util.List;

public class Main {
    public static boolean isNamedProcess(Context context, String processName) {
        if (null == context) {
            return false;
        }

        int pid = android.os.Process.myPid();
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> processInfoList = am.getRunningAppProcesses();
        if (null == processInfoList) {
            return true;
        }

        for (RunningAppProcessInfo info : processInfoList) {
            if (pid == info.pid && processName.equals(info.processName)) {
                return true;
            }
        }
        return false;
    }
}