Detailed explanation of Android SMS sending function examples

This paper analyzes the method of Android to realize the function of sending short messages. Share with you for your reference, as follows:

SMS, like making a phone call, is the basic function of Android mobile phone. The following is an example to illustrate how Android realizes the function of sending SMS.

The procedure is as follows:

Androidmanifest.xml is as follows:

When the pendingintent object is received, the broadcast action will be performed, just like the context. Sendbroadcast() method, which is why pendingintent needs to be passed in the smsmanager. Sendtextmessage() method as one of the service parameters.

When I write this program, I directly enter the test through my android smartphone. If there is no android 2.3.3 smartphone nearby, it doesn't matter. You can open two Android simulators through the following methods, one to send information and the other to receive information:

1、 First compile and run the program with eclipse, and then open the first simulator

2、 Open a DOS window (CMD) and enter the following command: D: \ > CD D: \ SDK \ Android \ tools\

3、 Enter shell command D: \ SDK \ Android \ Tools > emulator - Data foo

After these steps, a second simulator will appear. Use the instanceid (e.g. 5546) in the upper left as the recipient's phone number to test the status of SMS delivery.

Sometimes the content of our SMS is likely to exceed 70 words, and we don't want to input paragraph by paragraph. We want to input it directly, and then let the mobile phone automatically help us split it into 70 word SMS. What should we do?

At this time, a method of smsmanager will be used:

When the SMS content exceeds 70 words, this method will automatically help us divide the SMS into several SMS with no more than 70 words, and the return type of dividemessage() method is ArrayList, and then send it circularly through sendtextmessage().

Finally, you should pay attention to adding the permission to send SMS in androidmanifest, as shown below:

More readers interested in Android related content can view the special topics of this site: summary of Android resource operation skills, introduction and advanced tutorial of Android development, summary of Android control usage, summary of Android SMS and phone operation skills, and summary of Android multimedia operation skills (audio, video, recording, etc.)

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>