How to send text messages in Android

Source: Internet
Author: User

Sending text messages in Android is actually very simple. If you want to call the local text message system, you can use intent. The main code is as follows:

Uri uri = URI. parse ("smsto: 00000000000 ");

Intent it = new intent (intent. action_sendto, Uri );

It. putextra ("sms_body", "The smstext ");

Startactivity (it );

String body = "this is SMS Demo ";

Intent mmsintent = new intent (intent. action_sendto, Uri. fromparts ("smsto", number, null ));

Mmsintent. putextra (messaging. key_action_sendto_message_body, body );

Mmsintent. putextra (messaging. key_action_sendto_compose_mode, true );

Mmsintent. putextra (messaging. key_action_sendto_exit_on_sent, true );

Startactivity (mmsintent );

The SMS system provided by the mobile phone is called here.

But what if I don't want to call the text message system and ask my mobile phone to send my information directly? First, we need to know the SIM card of our mobile phone:

SIM card data can be divided into four types:

The first type is fixed storage data. This type of data is written into the SIM card center before the mobile phone is sold, including the International Mobile User Identification Number (imsi), authentication key (Ki), authentication and encryption algorithm, and so on.

The second type is network-related data temporarily stored. For example, the location region identifier (LAI), the mobile user temporary identifier (tmsi), and the public telephone network code that is prohibited from access.

The third type is related business code, such as the personal identification code (PIN), unlock code (PUK), and billing rate.

The fourth category is the telephone number book, which is the phone number that a mobile user can enter at any time. Almost all user information is stored in SIM cards. Therefore, SIM cards are also called user information identification cards.

Imsi is a unique number that identifies the only user in the GSM and UMTS networks. It is stored in the SIM card of the mobile phone and will be sent to the network through the mobile phone. The unique correspondence between imsi and SIM.

IMEI is also a unique number that identifies the only mobile phone in the GSM and UMTS networks. It is usually printed under the cell phone's battery side, dial * #06 # To See It. The unique IMEI corresponds to the device.

1. IMEI does not exist in the SIM card. It is the serial number of the mobile phone.

2. Generally, the phone number we call does not exist in the SIM card. Although the SIM card contains a place that stores the SIM card's own number, this number is manually set and can be changed. SIM card recognition usually uses an imsi number, which is unique for SIM cards.

3. Using functions such as simgetrecordinfo to obtain the imsi Number of the SIM card depends on whether the device manufacturer has implemented this function. As far as I know, it can be obtained on the Dopod machine, but not on Lenovo's machine, but not on other machines.

4. IMEI and imsi can be obtained through the line operation function in RIL or TAPI.

The following code gets the local phone number:

Telephonymanager TM = (telephonymanager) This. getsystemservice (context. telephony_service );

String DeviceID = TM. getdeviceid ();

String Tel = TM. getline1number ();

String IMEI = TM. getsimserialnumber ();

String imsi = TM. getsubscriberid ();

Add permission:

<Uses-Permission Android: Name = "android. Permission. read_phone_state"/> (if you do not have the permission, an error is returned .)

Note that not all mobile phone numbers can be obtained. Only some of them can be obtained. This is because the mobile operator did not write the data of the mobile phone number into the SIM card. This is like a variable. When a mobile operator assigns a value to it, it naturally has a value. Null if no value is assigned. This is why many people cannot get their local numbers.

Glossary:

IMEI: (International Mobile Equipment Identity) is the abbreviation of an international mobile device identity code. It is an "electronic serial number" consisting of 15 digits ", it corresponds to each mobile phone, and the code is the only one in the world. Each mobile phone is assigned a unique group of numbers in the world after it is assembled. This number will be recorded by the manufacturer who manufactures it from production to delivery.

Msi :( internationalmobilesubscriberidentificationnumber) the International Mobile User identification code, which is used to distinguish mobile users. It is stored in SIM cards and can be used to distinguish valid information of mobile users. The total length is no more than 15 characters ~ 9. Among them, MCC is the country code of the mobile user, which accounts for three digits. China's MCC stipulates that it is 460. MNC is a mobile network number, which consists of up to two digits, msin is a mobile user identification code used to identify the mobile users in a mobile communication network.

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.