Project requirements to do three network products, the three single-network SDK to integrate themselves into a three-network joint, the idea is probably in oncreate when differentiated operators
Sets an enumeration that assigns enumeration variables based on the SIM information that is taken, and some operations on the following three nets are judged by the enumeration
Set up operator enumeration first
Enum Carrieroperator{none (0), MM (1), Unipay (2), EGAME (3);p rivate int value; Private Carrieroperator (int i) { this.value=i; } public int GetValue () { return this.value; }} Carrieroperator carrieroperator = Carrieroperator. NONE;
Here's the carrier that gets 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 operator
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;}}
Article original, reproduced please specify
Android Get carrier information