Android gps kullanmadan location bulmak / ulke

location u netwerk e gore yani GSM yada WIFI yi kullanarak bulan fonksiyon asagidaki, direk alip yapistirabilirsiniz fonksiyon String dondurecek..

public static String getUserCountry(Context context) {
try {
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
final String simCountry = tm.getSimCountryIso();
if (simCountry != null && simCountry.length() == 2) { // SIM country code is available
return simCountry.toLowerCase(Locale.US);
}
else if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) { // device is not 3G (would be unreliable)
String networkCountry = tm.getNetworkCountryIso();
if (networkCountry != null && networkCountry.length() == { // network country code is available
return networkCountry.toLowerCase(Locale.US);
}
}
}
catch (Exception e) { }
return null;
}
Show your support

Clapping shows how much you appreciated Sevki Cetiner’s story.