src/main/java/com/simpligility/maven/plugins/android/standalonemojos/RunMojo.java
private void launch( final LauncherInfo info ) throws MojoExecutionException, MojoFailureException
    {
        final String command;
        
        final int debugPort = findDebugPort();

        command = String.format( "am start %s-n %s/%s", debugPort >= 0 ? "-D " : "", info.packageName, info.activity );

        doWithDevices( new DeviceCallback()
        {
            @Override
            public void doWithDevice( IDevice device ) throws MojoExecutionException, MojoFailureException
            {
                String deviceLogLinePrefix = DeviceHelper.getDeviceLogLinePrefix( device );

                try
                {
                    getLog().info( deviceLogLinePrefix + "Attempting to start " + info.packageName + "/" 
                            + info.activity );

                    CollectingOutputReceiver shellOutput = new CollectingOutputReceiver();
                    device.executeShellCommand( command, shellOutput );
                    if ( shellOutput.getOutput().contains( "Error" ) )
                    {
                        throw new MojoFailureException( shellOutput.getOutput() );
                    }
                    if ( debugPort > 0 ) 
                    {
                        int pid = findPid( device, "ps" );
                        if ( pid == -1 )
                        {
                            pid = findPid( device, "ps -Af" );
                        }
                        if ( pid == -1 )
                        {
                            throw new MojoFailureException( "Cannot find stated process " + info.packageName );
                        }
                        getLog().info(
                            deviceLogLinePrefix + "Process " + debugPort + " launched"
                        );
                        try 
                        {
                            createForward( device, debugPort, pid );
                            getLog().info(
                                deviceLogLinePrefix + "Debugger listening on " + debugPort
                            );
                        } 
                        catch ( Exception ex ) 
                        {
                            throw new MojoFailureException( 
                                "Cannot create forward tcp: " + debugPort 
                                    + " jdwp: " + pid, ex 
                            );
                        }
                    }
                }
                catch ( IOException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Input/Output error", ex );
                }
                catch ( TimeoutException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Command timeout", ex );
                }
                catch ( AdbCommandRejectedException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "ADB rejected the command", ex );
                }
                catch ( ShellCommandUnresponsiveException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Unresponsive command", ex );
                }
            }

            private int findPid( IDevice device, final String cmd )
            throws IOException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException
            {
                CollectingOutputReceiver processOutput = new CollectingOutputReceiver();
                device.executeShellCommand( cmd, processOutput );
                BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) );
                int pid = -1;
                for ( ;; )
                {
                    String line = r.readLine();
                    if ( line == null )
                    {
                        break;
                    }
                    if ( line.endsWith( info.packageName ) )
                    {
                        String[] values = line.split( " +" );
                        if ( values.length > 2 )
                        {
                            pid = Integer.valueOf( values[1] );
                            break;
                        }
                    }
                }
                r.close();
                return pid;
            }
        } );
    }
private void launch( final LauncherInfo info ) throws MojoExecutionException, MojoFailureException
    {
        final String command;
        
        final int debugPort = findDebugPort();

        command = String.format( "am start %s-n %s/%s", debugPort >= 0 ? "-D " : "", info.packageName, info.activity );

        doWithDevices( new DeviceCallback()
        {
            @Override
            public void doWithDevice( IDevice device ) throws MojoExecutionException, MojoFailureException
            {
                String deviceLogLinePrefix = DeviceHelper.getDeviceLogLinePrefix( device );

                try
                {
                    getLog().info( deviceLogLinePrefix + "Attempting to start " + info.packageName + "/" 
                            + info.activity );

                    CollectingOutputReceiver shellOutput = new CollectingOutputReceiver();
                    device.executeShellCommand( command, shellOutput );
                    if ( shellOutput.getOutput().contains( "Error" ) )
                    {
                        throw new MojoFailureException( shellOutput.getOutput() );
                    }
                    if ( debugPort > 0 ) 
                    {
                        int pid = findPid( device, "ps" );
                        if ( pid == -1 )
                        {
                            pid = findPid( device, "ps -Af" );
                        }
                        if ( pid == -1 )
                        {
                            throw new MojoFailureException( "Cannot find stated process " + info.packageName );
                        }
                        getLog().info(
                            deviceLogLinePrefix + "Process " + debugPort + " launched"
                        );
                        try 
                        {
                            createForward( device, debugPort, pid );
                            getLog().info(
                                deviceLogLinePrefix + "Debugger listening on " + debugPort
                            );
                        } 
                        catch ( Exception ex ) 
                        {
                            throw new MojoFailureException( 
                                "Cannot create forward tcp: " + debugPort 
                                    + " jdwp: " + pid, ex 
                            );
                        }
                    }
                }
                catch ( IOException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Input/Output error", ex );
                }
                catch ( TimeoutException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Command timeout", ex );
                }
                catch ( AdbCommandRejectedException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "ADB rejected the command", ex );
                }
                catch ( ShellCommandUnresponsiveException ex )
                {
                    throw new MojoFailureException( deviceLogLinePrefix + "Unresponsive command", ex );
                }
            }

            private int findPid( IDevice device, final String cmd )
            throws IOException, TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException
            {
                CollectingOutputReceiver processOutput = new CollectingOutputReceiver();
                device.executeShellCommand( cmd, processOutput );
                BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) );
                int pid = -1;
                for ( ;; )
                {
                    String line = r.readLine();
                    if ( line == null )
                    {
                        break;
                    }
                    if ( line.endsWith( info.packageName ) )
                    {
                        String[] values = line.split( " +" );
                        if ( values.length > 2 )
                        {
                            pid = Integer.valueOf( values[1] );
                            break;
                        }
                    }
                }
                r.close();
                return pid;
            }
        } );
    }
private void launch ( final LauncherInfo info ) throws MojoExecutionException , MojoFailureException { final String command ; final int debugPort = findDebugPort ( ) ; command = String . format ( "am start %s-n %s/%s" , debugPort >= 0 ? "-D " : "" , info . packageName , info . activity ) ; doWithDevices ( new DeviceCallback ( ) { @ Override public void doWithDevice ( IDevice device ) throws MojoExecutionException , MojoFailureException { String deviceLogLinePrefix = DeviceHelper . getDeviceLogLinePrefix ( device ) ; try { getLog ( ) . info ( deviceLogLinePrefix + "Attempting to start " + info . packageName + "/" + info . activity ) ; CollectingOutputReceiver shellOutput = new CollectingOutputReceiver ( ) ; device . executeShellCommand ( command , shellOutput ) ; if ( shellOutput . getOutput ( ) . contains ( "Error" ) ) { throw new MojoFailureException ( shellOutput . getOutput ( ) ) ; } if ( debugPort > 0 ) { int pid = findPid ( device , "ps" ) ; if ( pid == - 1 ) { pid = findPid ( device , "ps -Af" ) ; } if ( pid == - 1 ) { throw new MojoFailureException ( "Cannot find stated process " + info . packageName ) ; } getLog ( ) . info ( deviceLogLinePrefix + "Process " + debugPort + " launched" ) ; try { createForward ( device , debugPort , pid ) ; getLog ( ) . info ( deviceLogLinePrefix + "Debugger listening on " + debugPort ) ; } catch ( Exception ex ) { throw new MojoFailureException ( "Cannot create forward tcp: " + debugPort + " jdwp: " + pid , ex ) ; } } } catch ( IOException ex ) { throw new MojoFailureException ( deviceLogLinePrefix + "Input/Output error" , ex ) ; } catch ( TimeoutException ex ) { throw new MojoFailureException ( deviceLogLinePrefix + "Command timeout" , ex ) ; } catch ( AdbCommandRejectedException ex ) { throw new MojoFailureException ( deviceLogLinePrefix + "ADB rejected the command" , ex ) ; } catch ( ShellCommandUnresponsiveException ex ) { throw new MojoFailureException ( deviceLogLinePrefix + "Unresponsive command" , ex ) ; } } private int findPid ( IDevice device , final String cmd ) throws IOException , TimeoutException , AdbCommandRejectedException , ShellCommandUnresponsiveException { CollectingOutputReceiver processOutput = new CollectingOutputReceiver ( ) ; device . executeShellCommand ( cmd , processOutput ) ; BufferedReader r = new BufferedReader ( new StringReader ( processOutput . getOutput ( ) ) ) ; int pid = - 1 ; for ( ; ; ) { String line = r . readLine ( ) ; if ( line == null ) { break ; } if ( line . endsWith ( info . packageName ) ) { String [ ] values = line . split ( " +" ) ; if ( values . length > 2 ) { pid = Integer . valueOf ( values [ 1 ] ) ; break ; } } } r . close ( ) ; return pid ; } } ) ; }
Executes the "Launcher activity".

@param info A {@link LauncherInfo}.
@throws MojoFailureException
@throws MojoExecutionException
Executes the Launcher activity .