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