Created
November 8, 2018 18:13
-
-
Save shawnfeng0/445aee6505cf1a39353eea333e851fa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Is the Android service running? | |
* @param context The current context. | |
* @param serviceClass The service to get running state. | |
* @return true: if service is running. | |
*/ | |
static boolean isServiceRunning(Context context, Class<?> serviceClass) { | |
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); | |
if (manager == null) return false; | |
for (ActivityManager.RunningServiceInfo serviceInfo : manager.getRunningServices(Integer.MAX_VALUE)) { | |
if (serviceInfo.service.getClassName().equals(serviceClass.getName())) { | |
return true; | |
} | |
} | |
return false; | |
} | |
/** | |
* Find integer string from a string. | |
* @param str The string to get integer string. | |
* @return The resulting integer string. | |
*/ | |
static List<String> findIntegerString(String str) { | |
List<String> result = new ArrayList<>(); | |
Pattern pattern = Pattern.compile("\\d+"); | |
Matcher matcher = pattern.matcher(str); | |
while (matcher.find()) { | |
result.add(str.substring(matcher.start(),matcher.end())); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment