Android Get carrier information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.