Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SMS push of Android

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use SMS push of Android". In daily operation, I believe many people have doubts about how to use SMS push of Android. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use SMS push of Android". Next, please follow the editor to study!

Short message (SMS) Push and Ip push are two common push methods.

This article mainly briefly talks about Sms push.

The principle of Sms push:

Sms push achieves the purpose of notifying the terminal by sending binary SMS to the mobile terminal. The client intercepts this kind of SMS, analyzes the data of the SMS PDU, and then takes the corresponding action. Push messages are carried through Wap push. Its content includes two parts: the header and the data. the header should contain the destination port and the original port number (comparable to IP messages).

Because sending SMS requires the support of operators, such as Mobile Mail push Gateway (GEGW:GPRS Email Gateway), it is highly dependent.

Android client intercepts SMS processing:

The client statically registers a broadcast receiver that can intercept text messages even if the application is not running.

In this way, when the push message is sent (listening to the data on port 16001), the system initiates Intent to activate the broadcast receiver, and the broadcast receiver handles it in its event callback function.

Override public void onReceive (Context context, Intent intent) {String action = intent.getAction (); if (TextUtils.equals (action, "android.intent.action.DATA_SMS_RECEIVED")) {handleDataSmsReceived (context, intent);}}

In the processing function handleDataSmsReceived, the pdu data is obtained and parsed to understand how the server's data has changed, and the client can deal with it accordingly.

The simple implementation code is as follows:

Private void handleDataSmsReceived (Context context, Intent intent) {Uri uri = intent.getData (); int port = uri.getPort (); / / accept port 16001 SmsMessage [] msgs = getMessagesFromIntent (intent); String senderNumber = msgs [0] .getOriginatingAddress () / / the phone number of the SMS sender int type = parse (msgs) / / parses the business data of pdu, and decodes switch (type) {/ / different situations according to the protocol interacting with the server}}

The method of getting the text message

Private static final SmsMessage [] getMessagesFromIntent (Intent intent) {Object [] messages = (Object []) intent.getSerializableExtra ("pdus"); byte [] [] pduObjs = new byte [messages.length] []; for (int I = 0; I < messages.length; ionization +) {pduObjs [I] = (byte []) messages [I];} byte [] [] pdus = new byte [pduObjs.length] [] Int pduCount = pdus.length; SmsMessage [] msgs = new SmsMessage [pduCount]; for (int I = 0; I < pduCount; I +) {pdus [I] = pduObjs [I]; msgs [I] = SmsMessage.createFromPdu (pdus [I]);} return msgs At this point, the study on "how to use Android's SMS push" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report