Functional Requirements:
- After an article, if the SIM card changes, then send an alert SMS to the security number
- Receive the SMS sent from the security number, if the content is an alarm command, then according to the corresponding alarm command to make the corresponding operation
Send SMS
1. Create a Smsmanager object
Smsmanager manager = Smsmanager.getdefault ();
2. Get the security number by sharedpreferences String numbers
3. Create a text message: content
4. Split SMS: Since each text message can only be 70 words, so we want to split it: manager.divide (content); Returns a collection that stores a string
5. Send SMS:
Manager.sendtextmessage (destination phone number, NULL, SMS content, NULL, NULL);
6. Permission to apply: Send_sms
Code implementation:
//1. Creating a Smsmanager ObjectSmsmanager manager = Smsmanager.getdefault ();//2. Obtaining a security Number StringMobilenumber = sp.getstring ("Safenumber",NULL);//3. Creating SMS Content StringMessageText ="Security Alert! Your phone SIM card changes, suspected stolen, please send a command to open the anti-theft protection mechanism: \ n "+"Turn on GPS tracking, send #*location*# \ n"+"Play alarm music please send #*alarm*# \ n"+"remotely delete data please send #*wipedata*# \ n"+"Remote lock screen please send #*lockscreen*#"; arraylist<String> texts = manager.dividemessage (MessageText); for(Stringsms:texts) {manager.sendtextmessage (Mobilenumber,NULLSmsNULL,NULL); Toast.maketext (Context,sms,toast.length_short). Show (); }
Receive SMS
Receiving a message is a way to receive a broadcast
1. Create a class that inherits from Broadcastreceiver
2. Register the class with the manifest file:
<intent-filter> <action android:name="android.provider.telephony.SMS_RECEIVED"/><intent-filter>
3. Permission Receive_sms
4. Perform the receive SMS operation in the OnReceive () method
Copyright notice: Just out of the original content of the pot, I hope you have help ~
Mobile Security defender------mobile phone anti-theft page send SMS & Receive SMS