Android2.2 IccCard for application development (SIM card or USIM card)

Source: Internet
Author: User

 

If you want to display the mixed display of the phone card of the contacts in the android Address Book, the storage capacity of the phone card and the information that can be stored are different due to the different phone card types, it is necessary for android to read the information of the Icc card.

Generally, SIM cards can only store names and one phone number, while USIM cards can also store multiple phone numbers and mailboxes. Therefore, when editing contacts on the cards, they should be dynamically laid out, or the application can write to death, so that the storage information of the USIM card is consistent with that of the SIM card.

Because I am developing on the source code, some classes, methods, and attributes developed using the SDK may not be referenced. This is because Google does not have open APIs, so don't be confused.

1. Read ICC card type:

Because I only need to distinguish between sim and USIM, I think that the returned messages are not USIM. You can modify them as needed.

Import android. OS. SystemProperties;

Public String getSimType (){
If (SystemProperties. get ("gsm. sim. card. type", "SIM"). contentEquals ("USIM ")){
Return "USIM ";
} Else {
Return "SIM ";
}
}

2. Whether there is an ICC card:

Import android. telephony. TelephonyManager;

Boolean hasIcc = (TelephonyManager) getSystemService

(Context. TELEPHONY_SERVICE). hasIccCard ();

3. When to import SIM card contacts to mobile phone cards:

Generally, you will receive the boot_completed message and start a service for data export. I will tell you that the broadcast sent by a system is earlier than the boot_completed time.

Note: This broadcast will only be broadcast when a mobile phone card is inserted. It will not be broadcast without a plug-in.

Import com. android. internal. telephony. IccCard;
Import com. android. internal. telephony. TelephonyIntents;

 

[Java]
 
Public void onReceive (Context con, Intent intent ){
Log. I (TAG, "receive ");
If (intent. getAction (). equals (TelephonyIntents. ACTION_SIM_STATE_CHANGED )){
Log. I (TAG, "SIM_STATE_CHANGED" + intent. getStringExtra (IccCard. INTENT_KEY_ICC_STATE ));
If (intent. getStringExtra (IccCard. INTENT_KEY_ICC_STATE). equals (IccCard. INTENT_VALUE_ICC_LOADED )){
Log. I (TAG, "READY to start service ");
Intent I = new Intent (con, SimContactsService. class );
I. putExtra ("ICC_LOADED", "READY ");
Con. startService (I );
}
}
}


 

Yes, this broadcast is TelephonyIntents. ACTION_SIM_STATE_CHANGED; string: "android. intent. action. SIM_STATE_CHANGED ", the system attaches an IccCard to the intent when sending this action broadcast. INTENT_KEY_ICC_STATE data. When it comes to this, you should know that IccCard has several statuses. For details, you can check the source code. Here, when the status is IccCard. INTENT_VALUE_ICC_LOADED indicates that the mobile phone card has been loaded and the data of the mobile phone card can be read.

 

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.