InAndroidDuring use, if you want to eavesdrop on text messages received by others for your ulterior motives, the content in this section can meet your needs. When the system receives the text message,ActionName:Android. provider. Telephony. SMS_RECEIVEDBroadcast Intent, which stores the received text message content, using the name"Pdus"You can get text message content from Intent. The object array is obtained here, which is in the binary array format.
- Public class SmsBroadcastReceiver extends BroadcastReceiver {
- @ Override
- Public void onReceive (Context context, Intent intent ){
- Object [] pduses = (Object []) intent. getExtras (). get ("pdus ");
- For (Object pdus: pduses ){
- Byte [] pdusSms = (byte []) pdus;
- SmsMessage smsMessage = SmsMessage. createFromPdu (pdusSms );
- String mobile = smsMessage. getOriginatingAddress (); // get the SMS
- String content = smsMessage. getMessageBody (); // get the text message content
- Date date = new Date (smsMessage. getTimestampMillis (); // get the SMS sending time
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss ");
- String sendDate = simpleDateFormat. format (date );
- }
- }
- }
- In the <application> node of the AndroidManifest. xml file, connect to the broadcast Intent that receives the SMS for subscription:
- <Cycler android: name = ". IncomingSMSReceiver">
- <Intent-filter> <action android: name = "android. provider. Telephony. SMS_RECEIVED"/> </intent-filter> </receiver>
- Add the following permissions to the AndroidManifest. xml file:
- <Uses-permission android: name = "android. permission. RECEIVE_SMS"/> <! -- Receive SMS -->
- <Uses-permission android: name = "android. permission. SEND_SMS"/> <! -- Send SMS permission -->
Broadcast Receiver
In addition to the arrival of SMS broadcast Intent, Android also has many broadcast Intent types, such as startup, battery power change, and time change.
Receives the battery change broadcast Intent and subscribes to this Intent in the <application> node in the AndroidManifest. xml file :.
- <Cycler android: name = ". IncomingSMSReceiver">
- <Intent-filter>
- <Action android: name = "android. intent. action. BATTERY_CHANGED"/>
- </Intent-filter>
- </Cycler>
- Receive the boot broadcast Intent and subscribe to this Intent in the <application> node in the AndroidManifest. xml file:
- <Cycler android: name = ". IncomingSMSReceiver">
- <Intent-filter>
- <Action android: name = "android. intent. action. BOOT_COMPLETED"/>
- </Intent-filter>
- </Cycler>
And you need to declare the permission:
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Explanation of Android development instances: IMF
Android User Interface Design: Linear Layout
Android User Interface Design: Layout Basics
Google Android UI design skills: new UI design mode