/**
* 用来判断服务是否运行.
* @param context
* @param className 判断的服务名字:包名+类名
* @return true 在运行, false 不在运行
*/
public boolean isServiceRunning(Context context,String className) {
boolean isRunning = false;
ActivityManager activityManager =
(ActivityManager)context.getSystemService(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;
}
}
Log.i(TAG,"service is running?=="+isRunning);
return isRunning;
}
分享到:
相关推荐
Retrofit Love Working with APIs on Android
Android 检测判断手机的待机状态,比如手机正在处于待机状态、手机正在响铃、手机正在震动、手机已接听电话、手机正在连接来电等等的一些状态,使用了Case语句来判断各个状态。 case TelephonyManager.CALL_STATE_...
Working With Android ContactsWorking With Android ContactsWorking With Android Contacts
A good article about working with XML on Android.
Learn how to create effective REST clients on Android with Retrofit. Boost your productivity and enjoy working with complex APIs. Table of Contents Chapter 1 — Getting Started Chapter 2 — Requests ...
Part 1 What is Android? — The Big Picture 1 Targeting Android 1.1 Introducing Android 1.2 Stacking up Android 1.3 Booting Android development 1.4 An Android application 1.5 Summary 2 Development ...
Android Apps for Absolute Beginners: Covering Android 7 by Wallace Jackson English | 6 Apr. 2017 | ISBN: 1484222679 | 484 Pages | PDF | 26.76 MB Get your first Android apps up and running with the ...
Retrofit: Love Working with APIs on Android You need to take delight building API clients on Android. Marcus Pöhls
I: An Overview of the Android Platform 1 Introducing Android 11 A Brief History of Mobile Software Development 11 Way Back When 11 “The Brick” 13 Wireless Application Protocol (WAP) 15 Proprietary ...
Android Cookbook: Problems and Solutions for Android Developers by Ian F. Darwin English | 10 May 2017 | ASIN: B071VLZ9ZK | 838 Pages | AZW3 | 12 MB Jump in and build working Android apps with the ...
android studio 2015开发重点使用介绍
Beginning Android Tablet Programming then equips you to build a set of interesting and fully-working Android tablet applications. These projects will give you the inspiration and insights to build ...
Camera API in Android is hard. Having 2 different API for new and old Camera does not make things any easier. But fret not, that is your lucky day! After several years of working with Camera we came ...
Within minutes, “Hello, Android” will get you creating your first working application: Android’s version of “Hello, World.” From there, you’ll build up a more substantial example: an Android ...
Get started in creating marketable apps for the burgeoning Android market. Begin your journey by learning the essentials of programming for phones and tables that are built around Google's wildly-...
From using activities and intents and creating rich user interfaces to working with SMS, messaging APIs, and the Android SDK, what you need is here. Provides clear instructions backed by real-world ...
Android Recipes, Fourth Edition offers more than 100 down-to-earth code recipes, and guides you step-by-step through a wide range of useful topics using complete and real-world working code examples....
Library: BibTeX on Android License: Library is free software published under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007. Build (for dummies): Install and set up the Android SDK. ...