本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}