Android small feature realizes-sim card reading, texting, playing music

Source: Internet
Author: User

1. Read SIM card information

Private Telephonymanager TM; TM = (Telephonymanager) getsystemservice (Telephony_service); String sim = Tm.getsimserialnumber ();

Requires Telephonymanager and permissions
<uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>

2. Send SMS

Smsmanager Smsmanager = Smsmanager.getdefault (); smsmanager.sendtextmessage (phone, NULL, "MSG!", null, NULL);
Texting permission
<uses-permission android:name= "Android.permission.SEND_SMS"/>
Manager.sendtextmessage (Mobile,null,text,null,null);
First parameter: Phone number of the other person
Second parameter: SMS center number, generally set to empty
Third parameter: SMS content
The fourth parameter: Sentintent determine whether the text message is sent successfully, if you do not have a SIM card, or network interruption, you can use this intent to judge.
Note the emphasis is on whether the "send" action was successful. So as for whether or not the other party received
Fifth parameter: When a text message is sent to the recipient, it receives the deliveryintent. The result of "send" is emphasized.
This means that the two intent of sentintent and deliveryintent are activated when the message is sent successfully and the recipient receives this message. This is also equivalent to delaying the execution of the intent

3. Play Music

Create a music file to use for raw directory copies
Write code to play music:

MediaPlayer MediaPlayer =mediaplayer.create (context, R.raw.ylzs); Mediaplayer.setvolume (1.0f, 1.0f);// Channel mediaplayer.setlooping (FALSE);//Whether the loop plays Mediaplayer.start (); Abortbroadcast ();//4.3 version screen SMS Transceiver

Android small feature realizes-sim card reading, texting, playing music

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.