Android determines whether the SD card and SIM card are available

Source: Internet
Author: User

Sdcard and SIM card are used in a project. When using sdcard, You need to determine whether the status can be read and written. When using a SIM card, you must determine whether it is readable. For how to do this, see the following two functions:
 
// Whether sdcard can be read/written
Public boolean IsCanUseSdCard (){
Try {
Return Environment. getExternalStorageState (). equals (
Environment. MEDIA_MOUNTED );
} Catch (Exception e ){
E. printStackTrace ();
}
Return false;
}
// Whether the SIM card is readable
Public boolean isCanUseSim (){
Try {
TelephonyManager mgr = (TelephonyManager) getSystemService (Context. TELEPHONY_SERVICE );
 
Return TelephonyManager. SIM_STATE_READY = mgr
. GetSimState ();
} Catch (Exception e ){
E. printStackTrace ();
}
Return false;
}

Mainly used: android. telephony. TelephonyManager, android. OS. Environment, and android. app. Activity. getSystemService

Excerpt from: spiritual pure earth column

Related Article

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.