當前位置: 首頁>>代碼示例>>Java>>正文


Java ActivityManager.getRunningServices方法代碼示例

本文整理匯總了Java中android.app.ActivityManager.getRunningServices方法的典型用法代碼示例。如果您正苦於以下問題:Java ActivityManager.getRunningServices方法的具體用法?Java ActivityManager.getRunningServices怎麽用?Java ActivityManager.getRunningServices使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.ActivityManager的用法示例。


在下文中一共展示了ActivityManager.getRunningServices方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 用來判斷服務是否運行.
 * @param mContext
 * @param className 判斷的服務名字(例如:net.loonggg.testbackstage.TestService)
 * @return true 在運行 false 不在運行
 */
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(Integer.MAX_VALUE);
	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;
		}
	}
	return isRunning;
}
 
開發者ID:ebridfighter,項目名稱:GongXianSheng,代碼行數:24,代碼來源:CommonUtils.java

示例2: IsServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
public boolean IsServiceRunning(@NonNull Class<?> serviceClass) {
    ActivityManager activityManager = (ActivityManager) _context.getSystemService(Context.ACTIVITY_SERVICE);

    if (activityManager == null) {
        Logger.getInstance().Error(TAG, "ActivityManager is null!");
        return false;
    }

    for (RunningServiceInfo service : activityManager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }

    return false;
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:17,代碼來源:AndroidSystemController.java

示例3: isServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 判斷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;
}
 
開發者ID:zhuyu1022,項目名稱:amap,代碼行數:33,代碼來源:SystemUtils.java

示例4: onReceive

import android.app.ActivityManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent arg1) {
   

	 ActivityManager manager = (ActivityManager)context.   getSystemService(Context.ACTIVITY_SERVICE);
	 for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
{

    if (digiPune.class.getName().equals(service.service.getClassName())) {
                        //running 
       }
   else{
  	 context.startService(new Intent(context, digiPune.class));
       }

}
}
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:18,代碼來源:BootCompletedReceiver.java

示例5: isServiceWork

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 判斷某個服務是否正在運行的方法
 *
 * @param mContext
 * @param serviceName 是包名+服務的類名
 * @return true代表正在運行,false代表服務沒有正在運行
 */
public static boolean isServiceWork(Context mContext, String serviceName) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager) mContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.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;
}
 
開發者ID:kaixuanluo,項目名稱:pc-android-controller-android,代碼行數:25,代碼來源:ServiceManager.java

示例6: isMyServiceRunning2

import android.app.ActivityManager; //導入方法依賴的package包/類
private boolean isMyServiceRunning2(Class<NotificationService2> 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;
        }
    }
    return false;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:10,代碼來源:LaunchActivity.java

示例7: serviceIsRunningInForeground

import android.app.ActivityManager; //導入方法依賴的package包/類
public boolean serviceIsRunningInForeground(Context context) {
    Log.d(TAG, "serviceIsRunningInForeground()");
    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) {
                Log.d(TAG, "serviceIsRunningInForeground() - It is");
                return true;
            }
        }
    }
    Log.d(TAG, "serviceIsRunningInForeground() - It is NOT");
    return false;
}
 
開發者ID:stefanonicolai,項目名稱:AstronomyTourPadova,代碼行數:15,代碼來源:LocationService.java

示例8: getServiceInfo

import android.app.ActivityManager; //導入方法依賴的package包/類
private ActivityManager.RunningServiceInfo getServiceInfo() {
    ActivityManager manager = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> serviceInfoList = manager.getRunningServices(Integer.MAX_VALUE);
    for (ActivityManager.RunningServiceInfo service : serviceInfoList) {
        if (RemoteProcessService.class.getName().equals(service.service.getClassName())) {
            return service;
        }
    }
    return null;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:RealmInterprocessTest.java

示例9: isMyServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
public boolean isMyServiceRunning(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;
}
 
開發者ID:adityakamble49,項目名稱:gofun-app,代碼行數:12,代碼來源:ServiceUtils.java

示例10: isMyServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
private boolean isMyServiceRunning(Class<LocationData> locationDataClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (locationDataClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;

}
 
開發者ID:picopalette,項目名稱:event-me,代碼行數:11,代碼來源:EventDisplayActivity.java

示例11: isScreenFilterServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
public static boolean isScreenFilterServiceRunning(Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (MaskService.class.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:tranleduy2000,項目名稱:screenfilter,代碼行數:10,代碼來源:Utility.java

示例12: isRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
private boolean isRunning(Class<?> serviceClass) {
    ActivityManager mgr = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for(ActivityManager.RunningServiceInfo service : mgr.getRunningServices(Integer.MAX_VALUE)) {
        if(serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:CentriaUniversityOfAppliedSciences,項目名稱:Android_RuuvitagScannner,代碼行數:10,代碼來源:ScannerService.java

示例13: isMyServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
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;
        }
    }
    return false;
}
 
開發者ID:suhaas-livcd,項目名稱:Android_Labs,代碼行數:10,代碼來源:ActivityService.java

示例14: isUpdating

import android.app.ActivityManager; //導入方法依賴的package包/類
private boolean isUpdating() {
	ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
	for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
		if (UpdateService.class.getName().equals(service.service.getClassName()))
			return true;
	return false;
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:8,代碼來源:ActivityBase.java

示例15: isServiceRunning

import android.app.ActivityManager; //導入方法依賴的package包/類
/**
 * 判斷服務是否運行
 *
 * @param context   上下文
 * @param className 完整包名的服務類名
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isServiceRunning(Context context, String className) {
    ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> infos = activityManager.getRunningServices(0x7FFFFFFF);
    if (infos == null || infos.size() == 0) return false;
    for (RunningServiceInfo info : infos) {
        if (className.equals(info.service.getClassName())) return true;
    }
    return false;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:17,代碼來源:ServiceUtils.java


注:本文中的android.app.ActivityManager.getRunningServices方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。