@@ -88,7 +88,7 @@ private void run(String[] args) throws Exception {
8888
8989 if (op .equals ("start" )) {
9090 runStart ();
91- } else if (op .equals ("start-service " )) {
91+ } else if (op .equals ("startservice " )) {
9292 runStartService ();
9393 } else if (op .equals ("instrument" )) {
9494 runInstrument ();
@@ -181,6 +181,15 @@ private Intent makeIntent() throws URISyntaxException {
181181 return intent ;
182182 }
183183
184+ private void runStartService () throws Exception {
185+ Intent intent = makeIntent ();
186+ System .out .println ("Starting service: " + intent );
187+ ComponentName cn = mAm .startService (null , intent , intent .getType ());
188+ if (cn == null ) {
189+ System .err .println ("Error: Not found; no service started." );
190+ }
191+ }
192+
184193 private void runStart () throws Exception {
185194 Intent intent = makeIntent ();
186195 System .out .println ("Starting: " + intent );
@@ -240,19 +249,6 @@ private void runStart() throws Exception {
240249 }
241250 }
242251
243- private void runStartService () throws Exception {
244- Intent intent = makeIntent ();
245-
246- if (intent != null ) {
247- System .out .println ("Starting: " + intent );
248- try {
249- mAm .startService (null , intent , intent .getType ());
250- } catch (Exception e ) {
251- System .err .println ("Error: " + e );
252- }
253- }
254- }
255-
256252 private void sendBroadcast () throws Exception {
257253 Intent intent = makeIntent ();
258254 IntentReceiver receiver = new IntentReceiver ();
@@ -507,6 +503,8 @@ private static void showUsage() {
507503 " start an Activity: am start [-D] <INTENT>\n " +
508504 " -D: enable debugging\n " +
509505 "\n " +
506+ " start a Service: am startservice <INTENT>\n " +
507+ "\n " +
510508 " send a broadcast Intent: am broadcast <INTENT>\n " +
511509 "\n " +
512510 " start an Instrumentation: am instrument [flags] <COMPONENT>\n " +
0 commit comments