Java Android Studio - Recover device ip [duplicate]

0

Good morning, friends! Does anyone know how I can retrieve the ip of an android device? I got some codes, but only to recover ip from wifi. I need this ip, because I'm working on an ad application, and not to be counting multiple clicks for the advertiser, I would have to block this ip temporarily. Thank you in advance!

    
asked by anonymous 21.06.2018 / 14:29

1 answer

0

You can use a Webservice like AWS

import java.net.*;
import java.io.*;

URL meuIP = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(meuIP.openStream()));

String ip = in.readLine(); //você terá seu IP como uma String
System.out.println(ip);
    
21.06.2018 / 14:39