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.