String pid = String.format("/proc/%s", pId); File pidFile = new File(pid); boolean active = pidFile.exists();
如果不存在,可以通过如下方法启动服务。下面需要引用innerClass或者通过反射方法调用
IActivityManager am = ActivityManagerNative.getDefault(); Method method = null; try { // Build.SDK_INT >= 17 method = am.getClass().getMethod("startService", IApplicationThread.class, Intent.class, String.class, int.class); Object cn = method.invoke(am, null, intent, intent.getType(), 0); KLog.d(TAG, "start service return: " + cn); } catch (NoSuchMethodException e) {
}