user4847410
user4847410

Reputation:

Display text in Android

I know that System.out.println() does not work on Android.
So I need another way to print out some text.

Please help me.

I'm using the Root Tools library

class superuser  {
     public static Command c ;{
         if (RootTools.isRootAvailable()) {
             System.out.print("Root found!!");
         }
         else{ System.out.print(("NO ROOT!"));


         }
     }
 }

Upvotes: 0

Views: 111

Answers (4)

sudo_dudo
sudo_dudo

Reputation: 581

Outputing text in android

There are many ways, but usually for testing and debugging processes we use log. The log is not visible to user but you can see it in DDMS. From what i understand you want to create a dialog or display a textview to users so they know if root is available or not.


1.Logging(for testing and debugging processes)

we defined TAG in below code because it would be easy to make changes later and our code is more organised

private static final String TAG = MyActivity.class.getName();
Log.v(TAG , "here is the line i want to output in logcat");

here v in log.v stands for verbose.You may use i for info, e for error etc.

2.Displaying text to user via a TextView

First lets import the textview. Let the id of the textview you imported may be "resultTextView"

TextView resultText = (TextView) findViewById(R.id.resultTextView);

now applying your logic and setting its text...

     if (RootTools.isRootAvailable()) {
         resultText.setText("Root found!!");
     }
     else{ resultText.setText(("NO ROOT!"));


     }

3.Creating a dialog

Dialogs are the pop out messages we get. I would recommend creating a function that takes String message and a String Title as a parameter and creates a dialog using dialog.builder something like this rather than a dialog fragment(which is available in the below link) - http://developer.android.com/reference/android/app/AlertDialog.Builder.html

public void alertDialog(String message,String title){

        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            this);

        // set title
        alertDialogBuilder.setTitle(title);

        // set dialog message
        alertDialogBuilder
            .setMessage(message)
            .setPositiveButton("OK", null) //we write null cause we don't want 
//to perform any action after ok is clicked, we just want the message to disappear 


            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();
        }

Now you can call the method with title and text you want :)

Upvotes: 2

florent champigny
florent champigny

Reputation: 979

Using logcat is the usual way in Android, and the simplest.

Log.d("message_id","message content");

If you want another way to display log, you can try

https://github.com/orhanobut/logger

Upvotes: 0

Tahir Mehraj
Tahir Mehraj

Reputation: 9

if(condition){
 Log.d("message","The root found");
 }
else{
Log.d("message","The root not found");
 }

Upvotes: 2

svarog
svarog

Reputation: 9839

Have you tried using logcat ? http://developer.android.com/reference/android/util/Log.html

use it like so: Log.v("myAwesomeApp", "my developer comment");

then use the log panel in your IDE to read it

Upvotes: 0

Related Questions