Android programming timing SMS function example

This paper gives an example of Android programming to realize the function of sending short messages regularly. Share with you for your reference, as follows:

First, to realize the function of sending SMS, you must use the permission of sending SMS in Android system, that is, add the following contents to andoridmanifest.xml

Second, use AlarmManager to realize a countdown function and send SMS when the time comes. AlarmManager has two similar uses:

1. Perform an operation at a specified time. 2. Perform an operation periodically. The AlarmManager object needs to be used with the intent object. You can regularly start an activity, send a broadcast, or start a service.

Here are the core code snippets:

Third, realize the setting mode of time.

1. You can directly use the set method of the AlarmManager object to set the specific alarm time. 2. TimePicker can be used to set the time, which is more flexible.

Fourth, create a new alarmreceiver class to respond to the alarm clock.

1. Now add the declaration of receiver in androidmainfest.xml

The functions of obtaining time and sending short messages are realized in alarmreceiver.java. SMS sending requires smsmanager class, which is used to send messages. Smsmanager is a default instance of smsmanager

Its method is as follows

The meanings of each parameter are as follows:

Destinationaddress: recipient number scaddress: service number of SMS center, which is set to null here. Text: sending content sendintent: sending SMS result status signal (whether it has been successfully sent). New an intent. The operating system will broadcast this intent after receiving the signal. This process is asynchronous. Deliveryintent: the other party receives the status signal (whether it has been successfully received)

Finally, a detailed code is attached

For more Android related content, readers who are interested can view the special topics of this site: summary of Android SMS and phone operation skills, summary of Android file operation skills, summary of Android operation JSON format data skills, summary of activity operation skills of Android programming, introduction and advanced tutorial of Android development, summary of Android resource operation skills Android view skills summary and Android control usage summary

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
分享
二维码
< <上一篇
下一篇>>