0

I want to get smartphone's IP address by using socket class but my code dosent work.

button5.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {

             Socket mysocket = null;
              try {
                 Socket mysocket = new Socket("www.google.com", 80);
                 String Addr = mysocket.getLocalAddress().getHostAddress();
                 tv8.setText(Addr);
             }catch (Exception e){
                 tv8.setText("error");
             }
         }
     });

Is the code has anything wrong? it works in my phone but doesnt show IP address so I cant know what the problem is.

dogi B
  • 1

0 Answers0