Analysis of Android Mobile Guardian's Mobile Phone Realizing SMS Command to Obtain Location
- 2021-07-03 00:55:05
- OfStack
Recommended reading:
Analysis of Android Mobile Phone Guardian sim Card Binding
In-depth analysis of md5 encryption when Android mobile phone guard saves password
Explanation of Android Mobile Guardian Setup Wizard Page
Analysis of Android Mobile Phone Guardian Turning off Automatic Update
Analysis on the Attributes of Android Mobile Guardian Custom Control
Analysis on Android Mobile Phone Guardian Reading Contacts
Analysis on Android mobile phone guards receiving short message instructions and executing corresponding operations
Analysis on the principle of mobile phone positioning of Android mobile phone guard
Get the location
Create a new package for service
Create a new Service class of GPSService class inheritance system
Register 1 in the manifest file
Override the onCreate () method and call back when the service is created
Override the onDestroy () method and call back when the service is destroyed
Bring the code from the previous section to this place
Get the last position after the user moves, and save it to SP
Convert the standard coordinates to Mars coordinates, put the database file in the assets directory, and put ModifyOffset. java under the service package
Get the ModifyOffset object through the ModifyOffset. getInstance () method, parameter: input stream; Turn the files in the asset directory into an input stream, use getAssets (). open ("filename") to get the InputStream object,
Calling the s2c () method of the ModifyOffset object, converting the standard one into the Chinese one to get the new PointDouble object, parameters: PointDouble object, x, y
Gets the y of the longitude PonitDouble object
Gets the x to the latitude PonitDouble object
Save the location data in SP
Receive instruction and send location short message
Start the service, get the Intent object at the place where the short message is received, and call the startService () method of the Context object
Obtain the location information stored in SP
Send short message, SmsManager. getDefault (). sendTextMessage () method, send short message to security number, parameters: sendTextMessage (target mobile phone, null (source mobile phone does not support), text, sentIntent, deliveryIntent) last two parameters, delay report and delivery report, do not care to fill in null
This permission is required android.permission.SEND_SMS
Judge whether the content under 1 is empty. If it is empty, the content of sending short messages is being obtained. Manually change the coordinates under 1 before being obtained
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 SharedPreferences sp;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
// Service creation
@Override
public void onCreate() {
super.onCreate();
sp=getSharedPreferences("config", MODE_PRIVATE);
// Get 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);
}
// Destruction of services
@Override
public void onDestroy() {
super.onDestroy();
lm.removeUpdates(listener);
listener=null;
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// Obtain longitude
String longitude = "longitude : " + location.getLongitude();
String latitude = "latitude : " + location.getLatitude();
String acc = "accuracy : " + location.getAccuracy();
// Transform 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 onProviderEnabled(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 the content of SMS
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", "");
// SMS judged to be a secure number
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 location information
Intent intent1=new Intent(context,GPSService.class);
context.startService(intent1);
String lastLocation= sp.getString("lastlocation", "");
// Send a text message
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 a location message "+lastLocation);
abortBroadcast();
break;
default:
break;
}
}
}
}
}
The above is the site to introduce the Android mobile phone guard of the mobile phone to achieve SMS instructions to obtain the location of the relevant content, I hope to help you!