Domanda

I have a class with this code

public boolean busybox() throws IOException
{

        try
        {

        Process p =Runtime.getRuntime().exec("busybox");
        InputStream a = p.getInputStream();
        InputStreamReader read = new InputStreamReader(a);
        BufferedReader in = new BufferedReader(read);
        StringBuilder buffer = new StringBuilder();

        String line = null;

        try {

            while ((line = in.readLine()) != null) {
                buffer.append(line);
            }

        } finally {
            read.close();
            in.close();
        }

        String result = buffer.toString().substring(0, 15);
        System.out.println(result);

        return true;
        } catch (Exception e) {
        e.printStackTrace();
    }

        return false;
        }

In another class I have this code

try {
    if(root.busybox()) {

        Busybox.setText(Html.fromHtml((getString(R.string.busybox))));


    }
    else {

        Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
            }
        });

If I want to write in this TextView the outpout generated by System.out.println(result);

How can i do? Thanks in advance! I made several attempts, but I have several errors and the code is wrong.

È stato utile?

Soluzione

change return type of public boolean busybox() to string like public String busybox() and return result.

then use

try {
String myResult=root.busybox();  
if(myResult!=null&&myResult.length>0) {

    Busybox.setText(Html.fromHtml((myResult)));


}
else {

    Busybox.setText(Html.fromHtml((getString(R.string.no))));

    }
} 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top