SMS short message service processing and contact acquisition method developed by Android API

This paper describes the method of SMS service processing and obtaining contacts developed by Android API. Share with you for your reference, as follows:

The Android API supports the development of applications that can send and receive SMS messages. At present, the Android simulator used in our development process does not support sending SMS, but it can receive SMS. Now let's explore Android's support for SMS. We will build a small application to listen to SMS messages received on mobile devices (or simulators) and display them. Let's define an intent receiver to handle SMS receiving events:

We need to configure the intent receiver so that it can get SMS receiving events, Android provider. Telephony. SMS_ Received this event status indicates that the SMS has been received. We can do it at Android manifest XML is configured as follows:

In order to enable our application to receive SMS, we must specify the permission first, which can be found in androidmanifest XML is configured as follows:

Now, our intent receiver can be called when the Android device receives the SMS. The rest is to obtain and display the received SMS message text:

The SMS received by the Android device is in the form of PDU (protocol description unit). android. telephony. gsm. The smsmessage class can store SMS related information. We can also create a new smsmessage instance from the received PDU. The toast interface component can display the received SMS message text in the form of system notification.

Running program:

Now let's run the application in the simulator and send SMS messages to the simulator. We can send SMS messages to the simulator in the DDMS view (Dalvik debug monitor service) provided by the Android plug-in of eclipse (in the 'emulator control' panel; in addition, we need to specify the phone number, but it can be arbitrary)

Method of issuing broadcast intent:

Need to write another broadcast receiver:

Get contact information:

In Android manifest Add in XML:

More readers interested in Android related content 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 SQLite database operation skills, summary of Android JSON format data operation skills, summary of Android database operation skills, and summary of activity operation skills of Android programming , summary of SD card operation methods for Android programming development, introduction and advanced tutorial for Android development, summary of Android resource operation skills, summary of Android view skills, and summary of Android control usage

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