Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class GetPublicIP extends AsyncTask<String, String, String> {
- @Override
- protected String doInBackground(String... strings) {
- String publicIP = "";
- try {
- java.util.Scanner s = new java.util.Scanner(new java.net.URL("https://api.ipify.org")
- .openStream(), "UTF-8")
- .useDelimiter("\\A");
- publicIP = s.next();
- Log.d("TAG", "My current IP address is " + publicIP);
- } catch (java.io.IOException e) {
- e.printStackTrace();
- }
- return publicIP;
- }
- @Override
- protected void onPostExecute(String publicIp) {
- super.onPostExecute(publicIp);
- Log.d("TAG", publicIp + "");
- //Here 'publicIp' is your desire public IP
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement