@@ -31,7 +31,7 @@ private ServiceUtils() {
3131 *
3232 * @return all of the services are running
3333 */
34- public static Set getAllRunningServices () {
34+ public static Set < String > getAllRunningServices () {
3535 ActivityManager am = (ActivityManager ) Utils .getApp ().getSystemService (Context .ACTIVITY_SERVICE );
3636 List <RunningServiceInfo > info = am .getRunningServices (0x7FFFFFFF );
3737 Set <String > names = new HashSet <>();
@@ -61,8 +61,16 @@ public static void startService(@NonNull final String className) {
6161 * @param cls The service class.
6262 */
6363 public static void startService (@ NonNull final Class <?> cls ) {
64+ startService (new Intent (Utils .getApp (), cls ));
65+ }
66+
67+ /**
68+ * Start the service.
69+ *
70+ * @param intent The intent.
71+ */
72+ public static void startService (Intent intent ) {
6473 try {
65- Intent intent = new Intent (Utils .getApp (), cls );
6674 intent .setFlags (Intent .FLAG_INCLUDE_STOPPED_PACKAGES );
6775 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
6876 Utils .getApp ().startForegroundService (intent );
@@ -96,8 +104,22 @@ public static boolean stopService(@NonNull final String className) {
96104 * @return {@code true}: success<br>{@code false}: fail
97105 */
98106 public static boolean stopService (@ NonNull final Class <?> cls ) {
99- Intent intent = new Intent (Utils .getApp (), cls );
100- return Utils .getApp ().stopService (intent );
107+ return stopService (new Intent (Utils .getApp (), cls ));
108+ }
109+
110+ /**
111+ * Stop the service.
112+ *
113+ * @param intent The intent.
114+ * @return {@code true}: success<br>{@code false}: fail
115+ */
116+ public static boolean stopService (@ NonNull Intent intent ) {
117+ try {
118+ return Utils .getApp ().stopService (intent );
119+ } catch (Exception e ) {
120+ e .printStackTrace ();
121+ return false ;
122+ }
101123 }
102124
103125 /**
@@ -145,8 +167,33 @@ public static void bindService(@NonNull final String className,
145167 public static void bindService (@ NonNull final Class <?> cls ,
146168 @ NonNull final ServiceConnection conn ,
147169 final int flags ) {
148- Intent intent = new Intent (Utils .getApp (), cls );
149- Utils .getApp ().bindService (intent , conn , flags );
170+ bindService (new Intent (Utils .getApp (), cls ), conn , flags );
171+ }
172+
173+ /**
174+ * Bind the service.
175+ *
176+ * @param intent The intent.
177+ * @param conn The ServiceConnection object.
178+ * @param flags Operation options for the binding.
179+ * <ul>
180+ * <li>0</li>
181+ * <li>{@link Context#BIND_AUTO_CREATE}</li>
182+ * <li>{@link Context#BIND_DEBUG_UNBIND}</li>
183+ * <li>{@link Context#BIND_NOT_FOREGROUND}</li>
184+ * <li>{@link Context#BIND_ABOVE_CLIENT}</li>
185+ * <li>{@link Context#BIND_ALLOW_OOM_MANAGEMENT}</li>
186+ * <li>{@link Context#BIND_WAIVE_PRIORITY}</li>
187+ * </ul>
188+ */
189+ public static void bindService (@ NonNull final Intent intent ,
190+ @ NonNull final ServiceConnection conn ,
191+ final int flags ) {
192+ try {
193+ Utils .getApp ().bindService (intent , conn , flags );
194+ } catch (Exception e ) {
195+ e .printStackTrace ();
196+ }
150197 }
151198
152199 /**
0 commit comments