On the mobile phone of Android mobile phone to realize the location of SMS command acquisition _android

Source: Internet
Author: User
Tags md5 encryption

Recommended reading:

An analysis of Android phone defender SIM card binding

An in-depth analysis of the Android phone defender MD5 encryption when saving passwords

Detailed Android Phone Guardian Settings Wizard page

An analysis of Android phone defender turn off automatic Updates

A brief analysis of Android phone defender custom control properties

An analysis of Android phone defender reading contacts

On the Android handset Guardian receives the short message instruction to carry on the corresponding operation

On the principle of mobile phone positioning of Android mobile phone Guardian

Get location

Create a new service package

Create a new service class for the Gpsservice class inheritance system

Register in the manifest file

Overriding the OnCreate () method, which is invoked when the service is created

Rewrite OnDestroy () method, callback when service is destroyed

Get the code from the previous section to this place.

Get the last place the user moved, save to SP

Convert standard coordinates to Mars coordinates, database files in assets directory, put Modifyoffset.java under Service pack

Gets the Modifyoffset object, using the Modifyoffset.getinstance () method, parameters: input stream, converting the file in the asset directory into an input stream, and getassets (). Open ("filename") to get InputStream object ,

Call the Modifyoffset object's S2C () method, and convert the standard to Chinese to get the new Pointdouble object, Parameters: Pointdouble object, X, y

Gets the y of the Longitude Ponitdouble object

Gets the x of the Latitude Ponitdouble object

Save location data to SP

Receive instruction send location SMS

Start the service, where the message is received, get to the intent object, and invoke the StartService () method of the context object

Get the location information stored in the SP

Send SMS, Smsmanager.getdefault () Sendtextmessage () method, send SMS to security number, parameters: Sendtextmessage (target cell phone, null (source cell phone does not support), text, Sentintent, Deliveryintent) after two parameters, delayed reporting and delivery report, not concerned with filling null

This permission is required Android.permission.SEND_SMS

To determine whether the content is empty, if the empty text message is being obtained, manually let the coordinates change, in order to be

Gpsservice.java

Package com.qingguow.mobilesafe.service;
Import Android.app.Service;
Import android.content.Intent;
Import android.content.SharedPreferences;
Import Android.content.SharedPreferences.Editor;
Import Android.location.Criteria;
Import android.location.Location;
Import Android.location.LocationListener;
Import Android.location.LocationManager;
Import Android.os.Bundle;
Import Android.os.IBinder; public class Gpsservice extends Service {private Locationmanager lm; private Locationlistener listener; private Sharedpre
Ferences sp; 
@Override public IBinder onbind (Intent arg0) {return null;}//Service creation @Override public void OnCreate () {super.oncreate ();
Sp=getsharedpreferences ("config", mode_private);
Gets the location manager lm = (locationmanager) getsystemservice (Location_service);
Listener = new Mylocationlistener ();
Criteria criteria = new criteria ();
Criteria.setaccuracy (Criteria.accuracy_fine);
String Provider = Lm.getbestprovider (criteria, true);
Lm.requestlocationupdates (provider, 0, 0, listener); }
Service destruction @Override public void OnDestroy () {Super.ondestroy (); lm.removeupdates (listener); listener=null;} private Class Mylocationlistener implements Locationlistener {@Override public void onlocationchanged (Location Location) {//Get longitude Str
ing longitude = "Longitude:" + location.getlongitude ();
String latitude = "Latitude:" + location.getlatitude ();
String acc = "accuracy:" + location.getaccuracy ();
Convert Mars coordinates try {modifyoffset offset = modifyoffset.getinstance (Getassets (). Open ("Axisoffset.dat"));
Pointdouble pinit = offset.s2c (new pointdouble (location. Getlongitude (), Location.getlatitude ()));
Longitude = "Longitude:" + pinit.x;
Latitude = "Latitude:" + pinit.y;
catch (Exception e) {e.printstacktrace ();}//Save Data Editor editor=sp.edit ();
Editor.putstring ("Lastlocation", LONGITUDE+LATITUDE+ACC);
Editor.commit (); @Override public void onstatuschanged (String provider, int status, Bundle extras) {} @Override public void Onprovideren Abled (String provider) {} @Override public voiD onproviderdisabled (String provider) {}}} 

Smsreceiver.java

Package com.qingguow.mobilesafe.receiver;
Import Android.content.BroadcastReceiver;
Import Android.content.Context;
Import android.content.Intent;
Import android.content.SharedPreferences;
Import Android.media.MediaPlayer;
Import Android.telephony.SmsManager;
Import Android.telephony.SmsMessage;
Import Android.text.TextUtils;
Import COM.QINGGUOW.MOBILESAFE.R;
Import Com.qingguow.mobilesafe.service.GPSService;  public class Smsreceiver extends Broadcastreceiver {private sharedpreferences sp; @Override public void onreceive (context Context, Intent Intent) {sp=context.getsharedpreferences ("config", context.mode_private);//Get SMS Content object[] objs= (
Object[]) Intent.getextras (). Get ("PDUs");
for (Object obj:objs) {smsmessage SMS=SMSMESSAGE.CREATEFROMPDU ((byte[)) obj);
String Body=sms.getmessagebody ();
String sender=sms.getoriginatingaddress ();
String secsender=sp.getstring ("Secphone", ""); Judge is the security number of the SMS if (secsender.equals (sender)) {switch (body) {case "#*alarm*#"://Send alarm music//toast.maketext (contExt, "Play alarm Music", 1. Show ();
MediaPlayer mp=mediaplayer.create (context, r.raw.alarm);
Mp.start ();
Abortbroadcast ();
Break
Case "#*location*#"://Get position information Intent intent1=new Intent (context,gpsservice.class);
Context.startservice (INTENT1);
String lastlocation= sp.getstring ("Lastlocation", ""); Send SMS if (Textutils.isempty (lastlocation)) {Smsmanager.getdefault (). Sendtextmessage (sender, NULL, getting location ", NULL, NULL);}
else{Smsmanager.getdefault (). Sendtextmessage (sender, null,lastlocation, NULL, NULL);
System.out.println ("Get location Message" +lastlocation);
Abortbroadcast ();
Break
Default:break; }
}
}
}
}

The above is a small set to introduce the Android mobile phone Guardian mobile phone to achieve the location of the message command to obtain the relevant content, I hope to help you!

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.