首页 > 代码库 > Android 判断SIM卡属于哪个移动运营商

Android 判断SIM卡属于哪个移动运营商

package com.example.checksimoperator;import com.unity3d.player.UnityPlayer;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.telephony.TelephonyManager;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);                        Button close = (Button)this.findViewById(R.id.button0);        close.setOnClickListener(new OnClickListener() {            @Override            public void onClick(View v) {                                checkSIM();            }                    });    }                public void checkSIM(){        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();                System.out.print("此卡属于(中国移动)");              UnityPlayer.UnitySendMessage("Main Camera","Messgae","YD");                            } else if (operator.equals("46001")){                Toast.makeText(this, "此卡属于(中国联通)", Toast.LENGTH_SHORT).show();                  System.out.print("此卡属于(中国联通)");                UnityPlayer.UnitySendMessage("Main Camera","Messgae","LT");            } else if (operator.equals("46003")){                Toast.makeText(this, "此卡属于(中国电信)", Toast.LENGTH_SHORT).show();                      System.out.print("此卡属于(中国电信)");                UnityPlayer.UnitySendMessage("Main Camera","Messgae","DX");            }        }    }   }