Android obtains carrier Information
The project requires a three-network release product. The three single-network sdks are automatically integrated into the three networks. The idea is probably to divide the SDK into operators in the OnCreate time zone.
Set enumeration, assign enumeration variables based on the obtained SIM card information, and perform subsequent operations on the three networks based on enumeration.
Set carrier enumeration first
enum CARRIEROPERATOR{NONE(0),MM(1),UNIPAY(2),EGAME(3);private int value; private CARRIEROPERATOR(int i) { this.value=i; } public int getValue() { return this.value; }}CARRIEROPERATOR carrierOperator = CARRIEROPERATOR.NONE;
Which carrier is the SIM card?
Public int getSimOperatorInfo () {TelephonyManager telephonyManager = (TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE); String operatorString = telephonyManager. getSimOperator (); if (operatorString = null) {return 0;} if (operatorString. equals ("46000") | operatorString. equals ("46002") {// China Mobile return 1;} else if (operatorString. equals ("46001") {// China Unicom return 2;} else if (operatorString. equals ("46003") {// China Telecom return 3;} // errorreturn 0 ;}
Call the following function in the onCreate function to set the carrier
void SetCarrierOperation(){int simCode = GetSimOperatorInfo();switch(simCode){case 0:carrierOperator = CARRIEROPERATOR.NONE;break;case 1:carrierOperator = CARRIEROPERATOR.MM;break;case 2:carrierOperator = CARRIEROPERATOR.UNIPAY;break;case 3:carrierOperator = CARRIEROPERATOR.EGAME;break;default:Log.e("unity","SetCarrierOperation error");break;}}
Original article, reprinted please note