Code fetch IP gratis Untuk Android

Hallo kalian yang mau ngelihat IP taapi nggak tau kodenya disini aku kasih sesutau yaitu code fetch ip dari freegeoip.net itu gratis dan bisa gunaakan oleh umum.



dibawah ada code class fetch IP untuk Android studio atau serumpunnya :

public class FetchGeoIp extends AsyncTask<Void,Void,Void> {
    String data="";
    String dataIP="";
    String lines = "";

    @Override    protected Void doInBackground(Void... voids) {
        BufferedReader bufferedReader = null;
        try { 
            URL url = new URL("http://freegeoip.net/json/");
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            InputStream inputStream = httpURLConnection.getInputStream();
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = bufferedReader.readLine();

            while (line != lines) {
                data = line + "\n";
                lines = line;
            }

            JSONObject JO = new JSONObject(data);
            dataIP == "IP : "+JO.getString("ip")+"\n"+
                    "Country Code : "+JO.getString("country_code")+"\n"+
                    "Country Name : "+JO.getString("country_name")+"\n"+
                    "Region Code : "+JO.getString("region_code")+"\n"+
                    "Region Name : "+JO.getString("region_name")+"\n"+
                    "City : "+JO.getString("city")+"\n"+
                    "Zip Code : "+JO.getString("zip_code")+"\n"+
                    "Time Zone : "+JO.getString("time_zone")+"\n"+
                    "Latitude : "+JO.getString("latitude")+"\n"+
                    "Longitude : "+JO.getString("longitude")+"\n"+
                    "Metro Code : "+JO.getString("metro_code")+"\n\n\n";


        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        } 
        return null;
    }
    @Override    protected void onPreExecute() {
        super.onPreExecute();
        BaseMainActivity.data.setText("Loading...");
    }

    @Override    protected void onPostExecute(Void aVoid) {
        super.onPostExecute(aVoid);
        Log.d("IP2", "onPostExecute: "+dataIP);
        BaseMainActivity.data.setText(this.dataIP);
    }
}

Nah bagaimana ada yang bertanya silahkan.




1 Response to "Code fetch IP gratis Untuk Android"

  1. Really great post. I just discovered your web journal and needed to say that I have truly delighted in perusing your blog entries. Any way I'll be subscribing to your food and I trust you post again soon. Huge much obliged for the helpful information. cheat engine for android

    BalasHapus

Relevan Untuk Anda

Diberdayakan oleh Blogger.