Recommended reading:
Brief analysis of Android mobile phone guard sim card binding
An in-depth analysis of the md5 encryption when the Android mobile phone guard saves password
Detailed explanation of Android Mobile Phone Guard Settings Wizard Page
Brief analysis Android phone guard turns off automatic update
A brief analysis of the properties of Android mobile phone guard custom control
A brief analysis of Android mobile phone guard reading contact person
A brief analysis of Android mobile phone guard receiving SMS commands to perform corresponding operations
A brief analysis of the principle of Android mobile phone positioning
Get the location
Create a new service package
Create a new GPSService class inherits the service class of the system
Register in the manifest file
Rewrite the onCreate() method and callback when the service is created
Rewrite the onDestroy() method and callback when the service is destroyed
Take the code from the previous section to this place
Get the last location after the user moves, save it to SP
Convert the standard coordinates to Mars coordinates, put the database file in the assets directory, and place it under the service package
Get the ModifyOffset object, through the() method, parameters: input stream; convert the file in the asset directory into an input stream, use getAssets().open("file name") to obtain the InputStream object.
Call the s2c() method of the ModifyOffset object to convert the standard to China to get a new PointDouble object. Parameters: PointDouble object, x, y
Get the y of the longitude PonitDouble object
Get the x of the latitude PonitDouble object
Save location data to SP
Receive command send location text message
Start the service, get the Intent object at the place where the SMS is received, and call the startService() method of the Context object
Get the location information saved in the SP
Send SMS, ().sendTextMessage() method, send SMS to the security number, parameters: sendTextMessage (target mobile phone, null (source mobile phone does not support), text, sentIntent, deliveryIntent), delay report and delivery report, do not care about filling in null
This permission is required.SEND_SMS
Determine whether the content is empty. If the content is empty, the content is being retrieved. Manually change the coordinates to obtain it.
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class GPSService extends Service { private LocationManager lm; private LocationListener listener; private SharedPreferences sp; @Override public IBinder onBind(Intent arg0) { return null; } // Service creation@Override public void onCreate() { (); sp=getSharedPreferences("config", MODE_PRIVATE); // Get the location managerlm = (LocationManager) getSystemService(LOCATION_SERVICE); listener = new MyLocationListener(); Criteria criteria = new Criteria(); (Criteria.ACCURACY_FINE); String provider = (criteria, true); (provider, 0, 0, listener); } // Service destruction@Override public void onDestroy() { (); (listener); listener=null; } private class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location location) { // Get longitudeString longitude = "longitude:" + (); String latitude = "latitude:" + (); String acc = "accuracy:" + (); // Convert Mars coordinatestry { ModifyOffset offset = (getAssets() .open("")); PointDouble pinit = offset.s2c(new PointDouble(location .getLongitude(), ())); longitude = "longitude:" + ; latitude = "latitude:" + ; } catch (Exception e) { (); } //Save dataEditor editor=(); ("lastlocation", longitude+latitude+acc); (); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } } }
package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class SmsReceiver extends BroadcastReceiver { private SharedPreferences sp; @Override public void onReceive(Context context, Intent intent) { sp=("config", Context.MODE_PRIVATE); //Get text message contentObject[] objs=(Object[]) ().get("pdus"); for(Object obj:objs){ SmsMessage sms=((byte[])obj); String body=(); String sender=(); String secSender=("secphone", ""); //SMS that determines it is a safe numberif((sender)){ switch (body) { case "#*alarm*#"://send alarm music//(context, "play alarm music", 1).show();MediaPlayer mp=(context, ); (); abortBroadcast(); break; case "#*location*#"://get location informationIntent intent1=new Intent(context,); (intent1); String lastLocation= ("lastlocation", ""); //sending a text messageif((lastLocation)){ ().sendTextMessage(sender, null,"getting location", null, null); }else{ ().sendTextMessage(sender, null,lastLocation, null, null); } ("Get location message"+lastLocation); abortBroadcast(); break; default: break; } } } } }
The above is the relevant content about Android Mobile Defender’s mobile phone implementation of SMS commands to obtain locations, I hope it will be helpful to everyone!