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


Java RunningServiceInfo類代碼示例

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


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

示例1: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
private static boolean isServiceRunning(Context context) {
  boolean isRunning = false;
  ActivityManager activityManager = (ActivityManager) context
      .getSystemService(Context.ACTIVITY_SERVICE);
  List<RunningServiceInfo> serviceList = activityManager
      .getRunningServices(Integer.MAX_VALUE);

  if (serviceList == null || serviceList.size() == 0) {
    return false;
  }

  for (int i = 0; i < serviceList.size(); i++) {
    if (serviceList.get(i).service.getClassName().equals(
        DownloadService.class.getName())) {
      isRunning = true;
      break;
    }
  }
  return isRunning;
}
 
開發者ID:lifengsofts,項目名稱:AndroidDownloader,代碼行數:21,代碼來源:DownloadService.java

示例2: isServiceWork

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * 判斷某個服務是否正在運行的方法
 *
 * @param mContext
 * @param serviceName
 *            是包名+服務的類名(例如:net.loonggg.testbackstage.TestService)
 * @return true代表正在運行,false代表服務沒有正在運行
 */
public boolean isServiceWork(Context mContext, String serviceName) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager) mContext
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<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:z-chu,項目名稱:FriendBook,代碼行數:26,代碼來源:SystemTool.java

示例3: IsServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的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

示例4: checkServiceIsRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
public static boolean checkServiceIsRunning(Context context, String serviceName) {
    if (context == null || TextUtils.isEmpty(serviceName)) {
        return false;
    }
    ActivityManager manager = (ActivityManager) context.getSystemService("activity");
    if (manager == null) {
        return false;
    }
    List<RunningServiceInfo> list = manager.getRunningServices(Integer.MAX_VALUE);
    if (BaseTypeUtils.isListEmpty(list)) {
        return false;
    }
    for (RunningServiceInfo service : list) {
        if (service != null && service.service != null && serviceName.equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:LetvTools.java

示例5: isRunningService

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * 獲取服務是否開啟
 * @param className 完整包名的服務類名
 */
public static boolean isRunningService(String className, Context context) {
    // 進程的管理者,活動的管理者
    ActivityManager activityManager = (ActivityManager)
            context.getSystemService(Context.ACTIVITY_SERVICE);
    // 獲取正在運行的服務,最多獲取1000個
    List<RunningServiceInfo> runningServices = activityManager.getRunningServices(1000);
    // 遍曆集合
    for (RunningServiceInfo runningServiceInfo : runningServices) {
        ComponentName service = runningServiceInfo.service;
        if (className.equals(service.getClassName())) {
            return true;
        }
    }
    return false;
}
 
開發者ID:zhuangzaiku,項目名稱:AndroidCollection,代碼行數:20,代碼來源:UnclassifiedUtils.java

示例6: onReceive

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的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

示例7: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
private boolean isServiceRunning()
{
	boolean running = false;

	ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

	for(RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
	{
		if(SensorService.class.getName().equals(service.service.getClassName()))
		{
			running = true;
			break;
		}
	}

	return running;
}
 
開發者ID:piatt,項目名稱:GestureWave,代碼行數:18,代碼來源:SettingsActivity.java

示例8: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
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(30);

		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:Tencent,項目名稱:WeTest-Assistant,代碼行數:19,代碼來源:ApkManager.java

示例9: getData

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
@Override
    protected void getData() {

        List<RunningServiceInfo> liServices = m_activityManager.getRunningServices(MAXIMUM_SERVICES);
        List<RunningAppProcessInfo> runningAppProcesses = m_activityManager.getRunningAppProcesses();
        // liTasks.get(0).

        // Account[] accounts = m_activityManager.getAccounts();
        // String[] strAccountTypes = new String[accounts.length];
        //
        // for (int i = 0; i < accounts.length; i++) {
        // strAccountTypes[i] = accounts[i].type;
        // }

        if (!liServices.isEmpty()) {
            // TODO: implement logic
            StringBuilder sb = new StringBuilder();
            // for (int i = 0; i < liProcesses.size() - 1; i++)
            // sb.append(liProcesses.get.type + ";");
            // sb.append(liProcesses[liProcesses.length - 1]);

//			SensorRunningServices sensor = new SensorRunningServices();
//			// sensor.setAccountTypes(sb.toString());
//			handleDBEntry(sensor);
        }
    }
 
開發者ID:Telecooperation,項目名稱:assistance-platform-client-sdk-android,代碼行數:27,代碼來源:RunningAppsReaderSensor.java

示例10: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * @param context
 *            上下文對象
 * @param ServiceName
 *            要判斷的服務的名稱
 * @return 返回服務是否開啟狀態
 */
public static boolean isServiceRunning(Context context, String ServiceName) {

	// 拿到ActivityManager
	ActivityManager activityManager = (ActivityManager) context
			.getSystemService(Context.ACTIVITY_SERVICE);
	// 拿到所有運行的服務
	// 參數:要獲取的最大條數
	List<RunningServiceInfo> runningServices = activityManager
			.getRunningServices(200);
	for (RunningServiceInfo runningServiceInfo : runningServices) {
		// System.out.println(runningServiceInfo.service.getClassName());
		// 拿到服務的名稱
		String name = runningServiceInfo.service.getClassName();
		if (ServiceName.equals(name)) {
			return true;
		}
	}
	return false;
}
 
開發者ID:paifeng,項目名稱:Mobile-guards,代碼行數:27,代碼來源:ServiceStatusUtils.java

示例11: exitApp

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * 退出應用
 * @param context
 */
public static void exitApp(final Context context) {
    ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (context.getPackageName().equals(service.service.getPackageName())) {
            Intent stopIntent = new Intent();
            ComponentName serviceCMP = service.service;
            stopIntent.setComponent(serviceCMP);
            context.stopService(stopIntent);
            // new AppRecManager(context).unregisterListener();
            break;
        }
    }
    android.os.Process.killProcess(android.os.Process.myPid());
    System.exit(0);
}
 
開發者ID:feer921,項目名稱:BaseProject,代碼行數:20,代碼來源:PackageManagerUtil.java

示例12: isServiceWork

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/** 
 * 判斷某個服務是否正在運行的方法 
 * @param mContext 
 * @param serviceName 包名+服務的類名(例如:net.yunim.service.EBClientService)
 * @param mark 標記,僅用於打印日誌
 * @return true代表正在運行,false代表服務沒有正在運行 
 */
public static boolean isServiceWork(Context mContext, String serviceName, String mark) {
    boolean isWork = false;
    ActivityManager myAM = (ActivityManager)mContext.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> myList = myAM.getRunningServices(Integer.MAX_VALUE);
    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)) {
        	Log4jLog.d(LONG_TAG, "service '" + serviceName +"' is found, mark = " + mark);
            isWork = true;
            break;
        }
    }
    
    if (!isWork)
    	Log4jLog.e(LONG_TAG, "service '" + serviceName +"' is not exist, mark = " + mark);
    return isWork;  
}
 
開發者ID:entboost,項目名稱:EntboostIM,代碼行數:29,代碼來源:OtherUtils.java

示例13: isRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * Helper to query whether an application is currently running and its code has not been evicted from memory.
 *
 * @param context the Context
 * @param appName the package name or process name of the application.
 * @return true if the application is running, false otherwise.
 */
public static boolean isRunning(final Context context, String appName) {
    List<RunningAppProcessInfo> runningProcessInfo = Process.getRunningProcessInfo(context);
    List<RunningServiceInfo> services = Service.getRunningServiceInfo(context);

    for (RunningAppProcessInfo info : runningProcessInfo) {
        if (info.processName.equals(appName) &&
                info.importance != RunningAppProcessInfo.IMPORTANCE_EMPTY) {
            return true;
        }
    }

    for (RunningServiceInfo service: services) {
        String name = StringHelper.formatProcessName(service.process);
        if (name.equals(appName)) return true;
    }

    return false;
}
 
開發者ID:greenhub-project,項目名稱:batteryhub,代碼行數:26,代碼來源:Application.java

示例14: isServiceRunning

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * 用來判斷服務是否運行.
 *
 * @param context   the context
 * @param className 判斷的服務名字 "com.xxx.xx..XXXService"
 * @return true 在運行 false 不在運行
 */
public static boolean isServiceRunning(Context context, String className) {
    boolean isRunning = false;
    ActivityManager activityManager = (ActivityManager) context
            .getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> servicesList = activityManager
            .getRunningServices(Integer.MAX_VALUE);
    Iterator<RunningServiceInfo> l = servicesList.iterator();
    while (l.hasNext()) {
        RunningServiceInfo si = (RunningServiceInfo) l.next();
        if (className.equals(si.service.getClassName())) {
            isRunning = true;
        }
    }
    return isRunning;
}
 
開發者ID:KouChengjian,項目名稱:PhoneMate,代碼行數:23,代碼來源:AppUtil.java

示例15: isAlive

import android.app.ActivityManager.RunningServiceInfo; //導入依賴的package包/類
/**
 * 
 * @param context
 * @return whether EspPushService is alive background
 */
public static boolean isAlive(Context context)
{
    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningServiceInfo> list = am.getRunningServices(Integer.MAX_VALUE);
    boolean isServiceRunning = false;
    String clsName = EspPushService.class.getName();
    for (RunningServiceInfo info : list) {
        String serviceCls = info.service.getClassName();
        if (serviceCls.equalsIgnoreCase(clsName)) {
            isServiceRunning = true;
            break;
        }
    }
    return isServiceRunning;
}
 
開發者ID:EspressifApp,項目名稱:IOT-Espressif-Android,代碼行數:21,代碼來源:EspPushService.java


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