Android-Determine the status of the SIM card

Source: Internet
Author: User

Android determines the status of the SIM card and whether to insert the SIM card.
For example, determine the preferred network type based on SIM.

SIM card Status

    /** * Determine if the SIM card is included * * @return Status */     Public Static Boolean Hassimcard() {Context context = App.getappcontext (); Telephonymanager telmgr = (telephonymanager) context.getsystemservice (Context.telephony_service);intSimstate = Telmgr.getsimstate ();Booleanresult =true;Switch(simstate) { CaseTelephonyManager.SIM_STATE_ABSENT:result =false;//No SIM card                 Break; CaseTelephonyManager.SIM_STATE_UNKNOWN:result =false; Break; } log.d (TAG, result?)"SIM card":"No SIM card");returnResult }

All States

Telephonymanager telmgr = (telephonymanager) getsystemservice (Context.telephony_service);intSimstate = Telmgr.getsimstate ();Switch(simstate) { CaseTelephonymanager.sim_state_absent://Do something                 Break; CaseTelephonymanager.sim_state_network_locked://Do something                 Break; CaseTelephonymanager.sim_state_pin_required://Do something                 Break; CaseTelephonymanager.sim_state_puk_required://Do something                 Break; CaseTelephonymanager.sim_state_ready://Do something                 Break; CaseTelephonymanager.sim_state_unknown://Do something                 Break; }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android-Determine the status of the SIM card

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.