Last active
August 27, 2018 13:27
-
-
Save OkancanCosar/beba16426f90196b11b3860040651a3e to your computer and use it in GitHub Desktop.
getWifiSSID, getNetworkCountryIso, getNetworkOperator, getSimOperator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the SSID of the currently associated WiFi access point if there is one. Otherwise, | |
* returns empty string. | |
*/ | |
@CalledByNative | |
public static String getWifiSSID(Context context) { | |
if (context == null) { | |
return ""; | |
} | |
final Intent intent = context.registerReceiver( | |
null, new IntentFilter(WifiManager.NETWORK_STATE_CHANGED_ACTION)); | |
if (intent != null) { | |
final WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO); | |
if (wifiInfo != null) { | |
final String ssid = wifiInfo.getSSID(); | |
if (ssid != null) { | |
return ssid; | |
} | |
} | |
} | |
return ""; | |
} | |
/** | |
* Returns the ISO country code equivalent of the current MCC. | |
*/ | |
@CalledByNative | |
private static String getNetworkCountryIso(Context context) { | |
TelephonyManager telephonyManager = | |
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (telephonyManager == null) return ""; | |
return telephonyManager.getNetworkCountryIso(); | |
} | |
/** | |
* Returns the MCC+MNC (mobile country code + mobile network code) as | |
* the numeric name of the current registered operator. | |
*/ | |
@CalledByNative | |
private static String getNetworkOperator(Context context) { | |
TelephonyManager telephonyManager = | |
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (telephonyManager == null) return ""; | |
return telephonyManager.getNetworkOperator(); | |
} | |
/** | |
* Returns the MCC+MNC (mobile country code + mobile network code) as | |
* the numeric name of the current SIM operator. | |
*/ | |
@CalledByNative | |
private static String getSimOperator(Context context) { | |
TelephonyManager telephonyManager = | |
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); | |
if (telephonyManager == null) return ""; | |
return telephonyManager.getSimOperator(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment