is App Alive - Android App

Android examples for App:App Running

Description

is App Alive

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;

import android.text.TextUtils;
import java.util.List;

public class Main {

    public static boolean isAppAlive(String packageName, Context context) {
        if (context == null || TextUtils.isEmpty(packageName)) {
            return false;
        }/*from  w w w .  j ava 2s  . c o m*/

        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);

        if (activityManager != null) {
            List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager
                    .getRunningAppProcesses();
            if (procInfos != null && !procInfos.isEmpty()) {
                for (int i = 0; i < procInfos.size(); i++) {
                    if (procInfos.get(i).processName.equals(packageName)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
}

Related Tutorials