0

I would like to be able to detect the sim operator name and return a code if it is found. Please help me. below are the two methods from my code

//first method to detect sim Operator

private void simOperatorName() {
// TODO Auto-generated method stub
//operator gotten
final TelephonyManager telephonyManager = 
(TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
networkName =  telephonyManager.getSimOperatorName().toUpperCase();

if (networkName != null ){
network =  networkName;

}else {

 Log.d("LEE", "NETWORK OF THE SIM WAS NOT FOUND");          Toast.makeText(getApplicationContext(), 
"Please Network Not Found", Toast.LENGTH_LONG).show();
}
}

// second method

private String network() {
// TODO Auto-generated method stub
simOperatorName();

try {
if(network == "MTN"){
code = "*125*";
}else if (network == "VODAFONE") {
code= "*122*";
}else if (network == "TIGO") {
code = "*842*";
}else if (network == "GLO") {
code = "*123*";
}else if (network == "AIRTEL") {
code = "*134*";
} catch (Exception e) {
// TODO: handle exception
Log.d("LEE", "Network not Found");
Toast.makeText(getApplicationContext(),"Please Code otFound",Toast.LENGTH_LONG).show();
}return code;
}
Azeem
  • 33
  • 7
  • You should not use the == operator for String comparisons in Android or Java programming. Please see this Stack Overflow question and answer: http://stackoverflow.com/a/513839/314104 – user314104 Jul 08 '13 at 23:57
  • What error do you get? Have you added the `READ_PHONE_STATE` permission? – Ken Y-N Jul 09 '13 at 00:03
  • @user314104 and Ken Y-N thank I looked at the phone state again and the String comparison. but how do i use # as a string "#" doesnt seem to work when I add it to my number and try to call using the emulator – user2476688 – Azeem Jul 09 '13 at 00:28
  • What happens when you dial "#"? What were you expecting to happen? – user314104 Jul 12 '13 at 00:50
  • I want to load credit so eg. *123*1333242424# but the # is not detected. so its like *123*1333242424 instead. – Azeem Jul 12 '13 at 22:34

0 Answers0