Example usage for android.app ActivityManager getRunningServices

List of usage examples for android.app ActivityManager getRunningServices

Introduction

In this page you can find the example usage for android.app ActivityManager getRunningServices.

Prototype

@Deprecated
public List<RunningServiceInfo> getRunningServices(int maxNum) throws SecurityException 

Source Link

Document

Return a list of the services that are currently running.

Usage

From source file:uk.org.openseizuredetector.OsdUtil.java

public boolean isServerRunning() {
    //Log.v(TAG,"isServerRunning()................");
    ActivityManager manager = (ActivityManager) mContext.getSystemService(mContext.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        //Log.v(TAG,"Service: "+service.service.getClassName());
        if ("uk.org.openseizuredetector.SdServer".equals(service.service.getClassName())) {
            //Log.v(TAG,"Yes!");
            return true;
        }//from w  ww .ja  v a 2 s.co m
    }
    //Log.v(TAG,"No!");
    return false;
}

From source file:com.error.hunter.ListenService.java

private void generateBugReport(ActivityManager.ProcessErrorStateInfo entry) {

    String condition;/*from  w w  w . j  a v a  2  s  .  c  o m*/
    badProcess = entry.processName;
    String build = Build.DISPLAY;
    String fingerprint = Build.FINGERPRINT;
    String serial = Build.SERIAL;
    String product = Build.PRODUCT;
    String model = Build.MODEL;

    File path = Environment.getDataDirectory();
    StatFs stat = new StatFs(path.getPath());
    @SuppressWarnings("deprecation")
    long blockSize = stat.getBlockSize();
    @SuppressWarnings("deprecation")
    long availableBlocks = stat.getAvailableBlocks();
    String memory = Formatter.formatFileSize(this, availableBlocks * blockSize).toString();

    MemoryInfo mi = new MemoryInfo();
    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    activityManager.getMemoryInfo(mi);
    long availableMegs = mi.availMem / 1048576L;

    strBuf.append("Problem detected in: ").append(badProcess);
    if (entry.tag != null) {
        strBuf.append(" (").append(entry.tag).append(")");
    }
    strBuf.append("\nDevice product: " + product);
    strBuf.append("\nDevice model: " + model);
    strBuf.append("\nDevice build: " + build);
    strBuf.append("\nDevice fingerprint: " + fingerprint);
    strBuf.append("\nDevice SN: " + serial);
    strBuf.append("\nDevice available RAM (MB): " + availableMegs);
    strBuf.append("\nDevice free phisical memory: " + memory + "\n");
    strBuf.append(getNetworkInfo());
    strBuf.append("\n");

    ActivityManager actvityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> procInfos = actvityManager.getRunningServices(1000);
    Iterator<RunningServiceInfo> taskIter = procInfos.iterator();
    RunningServiceInfo info;
    while (taskIter.hasNext()) {
        info = taskIter.next();
        if (info.process.equals(badProcess)) {
            strBuf.append("\nService " + info.service + " crash count: " + info.crashCount + " active since: "
                    + info.activeSince + " process: " + info.process);
        }
    }
    strBuf.append("\n");
    //android.os.Debug.MemoryInfo[] miPid = activityManager.getProcessMemoryInfo(new int[]{entry.pid}); 
    //String memoryProc = miPid[0].toString();
    //strBuf.append("\nRAM used by process (Process: " + entry.processName + " PID: " + entry.pid +"): " + memoryProc + "MB\n");

    switch (entry.condition) {

    case ActivityManager.ProcessErrorStateInfo.CRASHED:
        condition = "CRASHED";
        getDeviceProcessInfo(badProcess, entry.stackTrace);
        writeLogsToFile(condition, badProcess);
        break;
    case ActivityManager.ProcessErrorStateInfo.NOT_RESPONDING:
        condition = "ANR";
        getDeviceProcessInfo(badProcess, "");
        writeLogsToFile(condition, badProcess);
        break;
    default:
        condition = "<unknown>";
        getDeviceProcessInfo(badProcess, entry.stackTrace);
        writeLogsToFile(condition, badProcess);
        break;
    }
}

From source file:fi.ohtu.mobilityprofile.ui.fragments.SettingsFragment.java

/**
 * Checks if PlaceRecorder is running.//from   www . j  ava 2 s . co m
 * @see PlaceRecorder
 * @return true/false
 */
private boolean isLocationServiceRunning() {
    ActivityManager manager = (ActivityManager) MainActivity.getContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (PlaceRecorder.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.github.opengarageapp.activity.MainActivity.java

public boolean isServiceRunning(String serviceClassName) {
    final ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);

    for (RunningServiceInfo runningServiceInfo : services) {
        if (runningServiceInfo.service.getClassName().equals(serviceClassName)) {
            return true;
        }/*from w w  w .j  ava2  s  .  c  o m*/
    }
    return false;
}

From source file:com.android.together.BaseActivity.java

/**
 * push //from   ww w. j  ava  2  s . c  o m
 */
private boolean isPushRunning() {
    // TODO Auto-generated method stub
    ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> serviceList = mActivityManager.getRunningServices(Integer.MAX_VALUE);

    for (RunningServiceInfo info : serviceList) {

        if (Constant.NAME_PUSH_SERVICE.equals(info.service.getClassName())) {
            return true;
        }
    }
    return false;
}

From source file:com.simas.vc.background_tasks.FFmpegService.java

private boolean isRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (getClass().getName().equals(service.service.getClassName())) {
            return true;
        }/* w  w  w .ja va  2s  . c  om*/
    }
    return false;
}

From source file:it.durip_app.TCPActivity.java

private boolean isIperfRunning() {
    String serviceName = "it.durip_app.Iperf";
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceName.equals(service.service.getClassName())) {
            return true;
        }//w  ww .  j a  v a 2  s . com
    }
    return false;
}

From source file:grupo19.locmess19.Services.LocationUpdatesService.java

public boolean serviceIsRunningInForeground(Context context) {

    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (getClass().getName().equals(service.service.getClassName())) {
            if (service.foreground) {
                return true;
            }//  w w  w  .j  a va 2 s. c o  m
        }
    }
    return false;
}

From source file:eu.codeplumbers.cosi.activities.CozyActivity.java

public boolean isMyServiceRunning() {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if ("eu.codeplumbers.attachmentbackup.app.services.ReklaimService"
                .equals(service.service.getClassName())) {
            return true;
        }/*from  w w w.ja  v a  2 s .co m*/
    }
    return false;
}

From source file:com.luan.thermospy.android.activities.MainActivity.java

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }// w  w w  .ja va 2 s. c  om
    }
    return false;
}