Display a parameter of my application on android with System.out.print

2

Hi, I have made a small application on android that is installed, but now I wanted to add an option so that I can use a domain instead of an IP. So to check if I really get the IP of my domain what I do is:

System.out.println("EJEMPLO"+giriAddress);

The complete code would be:

package my.app.client;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import my.app.client.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LauncherActivity extends Activity
    {
        /** Called when the activity is first created. */

        Intent Client, ClientAlt;
        // Button btnStart, btnStop;
        // EditText ipfield, portfield;
        private InetAddress giriAddress;

        public LauncherActivity()
        throws UnknownHostException
        {
            this.giriAddress=InetAddress.getByName("www.google.com");
            System.out.println("EJEMPLO"+giriAddress);

        }   
        //private String hostIP = giriAddress.getHostAddress() ;
        private String myIp = "IP"; // Put your IP in these quotes.
        private int myPort = PORT; // Put your port there, notice that there are no quotes here.

        @Override
        public void onStart()
            {
                super.onStart();
                onResume();
            }

        @Override
        public void onResume()
            {
                super.onResume();
                Client = new Intent(this, Client.class);
                Client.setAction(LauncherActivity.class.getName());
                getConfig();
                Client.putExtra("IP", myIp);
                Client.putExtra("PORT", myPort);

                startService(Client);
                moveTaskToBack(true);
            }

        @Override
        public void onCreate(Bundle savedInstanceState)
            {
                super.onCreate(savedInstanceState);
//              setContentView(R.layout.main);
                Client = new Intent(this, Client.class);
                Client.setAction(LauncherActivity.class.getName());
                getConfig();
                Client.putExtra("IP", myIp);
                Client.putExtra("PORT", myPort);

                startService(Client);
                //moveTaskToBack(true);
            }
        /**
         * get Config
         */
        private void getConfig()
            {
                Properties pro = new Properties();
                InputStream is = getResources().openRawResource(R.raw.config);
                try
                    {
                        pro.load(is);
                    } catch (IOException e)
                    {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                myIp = pro.getProperty("host");
                myPort = Integer.valueOf(pro.getProperty("prot"));
                System.out.println(myIp);
                System.out.println(myPort);
            }
    }

What I do is show it in my console but when the application starts and it is installed, my "EJEMPLO + IP" never appears:

How can I show this IP from my console, since it never shows it to my console!

    
asked by Sergio Ramos 25.05.2017 в 19:57
source

1 answer

0

The code block is simply not running because it is not causing an error:

 public LauncherActivity()
        throws UnknownHostException
        {
            this.giriAddress=InetAddress.getByName("www.google.com");
            System.out.println("EJEMPLO"+giriAddress);

        } 

If you cause an error, then you can see what you want to print, for example add within onCreateView() :

 throw new RuntimeException("Provocando un CRASH!");
    
answered by 25.05.2017 в 20:13