Mobile Security defender------mobile phone anti-theft page send SMS & Receive SMS

Source: Internet
Author: User

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

    • Create an array to store the SMS
      object[] Objs = Intent.getextras (). Get ("PDUs");

    • Read SMS Data
      for (Object Obj:objs)

    • Specific to a certain message
      Smsmessage SMS = SMSMESSAGE.CREATEFROMPDU ((byte[]) obj);
    • Get SMS Sender
      String sender = Message.getoriginatingaddress ();
    • Get SMS Content
      String BODY = Sms.getmessagebody ();
    • The broadcast priority to 1000, that is, the first to receive SMS
    • After the operation is completed, broadcast truncation is done to prevent other apps from receiving text messages
      Abortbroadcast ();

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

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.