Hi,
I have problems by using Java code for the first time. I don't know if it is my lack of knowledge or just not the right code.
I try:
This is the error during compile:
Compileren gegenereerde Java code. Error
src\ciris\chauffeur\main.java:1781: error: cannot find symbol
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
^
symbol: class TelephonyManager
location: class main
1 error
javac 11.0.1
Can somebody help me with this?
BR, André
I have problems by using Java code for the first time. I don't know if it is my lack of knowledge or just not the right code.
I try:
B4X:
Sub GetCountry As String
Private NativeMe As JavaObject
If(NativeMe.IsInitialized=False) Then NativeMe.InitializeContext
Dim s As String = NativeMe.RunMethod("getUserCountry", Null)
Log(s)
Return s
#if Java
/**
* Get ISO 3166-1 alpha-2 country code for this device (or null if not available)
* @param context Context reference to get the TelephonyManager instance from
* @return country code or null
*/
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() == 2) { // network country code is available
return networkCountry.toLowerCase(Locale.US);
}
}
}
catch (Exception e) { }
return null;
}
#End If
End Sub
This is the error during compile:
Compileren gegenereerde Java code. Error
src\ciris\chauffeur\main.java:1781: error: cannot find symbol
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
^
symbol: class TelephonyManager
location: class main
1 error
javac 11.0.1
Can somebody help me with this?
BR, André