我希望能够检测到sim运算符名称并返回代码(如果找到)。请帮我。以下是我的代码中的两种方法
//检测sim运算符的第一种方法
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();
}
}
//第二种方法
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;
}