android 判断SIM卡是哪个运营商
package com.eboy.checksimoperator;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void checkSIM(View v){
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String operator = telManager.getSimOperator();
if (operator != null){
if (operator.equals("46000") || operator.equals("46002")){
Toast.makeText(this, "此卡属于(中国移动)", Toast.LENGTH_SHORT).show();
} else if (operator.equals("46001")){
Toast.makeText(this, "此卡属于(中国联通)", Toast.LENGTH_SHORT).show();
} else if (operator.equals("46003")){
Toast.makeText(this, "此卡属于(中国电信)", Toast.LENGTH_SHORT).show();
}
}
}
}
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void checkSIM(View v){
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String operator = telManager.getSimOperator();
if (operator != null){
if (operator.equals("46000") || operator.equals("46002")){
Toast.makeText(this, "此卡属于(中国移动)", Toast.LENGTH_SHORT).show();
} else if (operator.equals("46001")){
Toast.makeText(this, "此卡属于(中国联通)", Toast.LENGTH_SHORT).show();
} else if (operator.equals("46003")){
Toast.makeText(this, "此卡属于(中国电信)", Toast.LENGTH_SHORT).show();
}
}
}
}