Android获取系统隐藏服务实现锁屏
Android获取系统隐藏服务实现锁屏
获取手机经纬度有 gps , network , 基站 三种方式,我们可以根据定位的条件,获取一个最好的定位方式。然后将获取到经纬度信息发送到指定的手机号码中。
- /*
- * 单态只允许存在一个实例.
- * 获取手机的gps信息
- */
- public class GPSInfoService {
- private Context context;
- private LocationManager manager;
- SharedPreferences sp ;
- //私有化构造方法
- private GPSInfoService(Context context){
- this.context= context;
- manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
- sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
- }
- private static GPSInfoService mGPSService;
- public synchronized static GPSInfoService getInstance(Context context){
- if(mGPSService==null)
- mGPSService = new GPSInfoService(context);
- return mGPSService;
- }
- /*
- * 当前你的手机 所支持的定位方式获取出来
- * 有多种定位方式 gps network ,基站, passive
- * 可以根据定位的条件 ,获取 一个最好的定位方式http://www.bkjia.com
- */
- public void registerLocationUpdates(){
- Criteria criteria = new Criteria();
- // 设置定位的精度
- criteria.setAccuracy(Criteria.ACCURACY_COARSE); //获取大体的位置
- criteria.setAltitudeRequired(false); // 海拔信息
- criteria.setCostAllowed(true); //允许产生费用
- criteria.setPowerRequirement(Criteria.POWER_LOW); //低功耗
- //获取一个最符合查询条件的位置提供者
- String provider =manager.getBestProvider(criteria, true);
- // 位置改变就会调用Linster的监听器 获取经度纬度
- manager.requestLocationUpdates(provider, 60000, 0, getLinster());
- }
- public void cancleLocationUpdates(){
- manager.removeUpdates(getLinster());
- }
- private static MyGPSLinster myGPSLinser;
- private MyGPSLinster getLinster(){
- if(myGPSLinser==null)
- myGPSLinser = new MyGPSLinster();
- return myGPSLinser;
- }
- private class MyGPSLinster implements LocationListener{
- // 用户位置改变的时候 的回调方法
- public void onLocationChanged(Location location) {
- //获取到用户的纬度
- double latitude= location.getLatitude();
- //获取到用户的经度
- double longitude = location.getLongitude();
- //进行封装写入到文件中
- String locationstr = "jing du "+ longitude + " weidu :"+latitude;
- Editor editor = sp.edit();
- editor.putString("lastlocation", locationstr);
- editor.commit();
- }
- // 状态改变
- public void onStatusChanged(String provider, int status, Bundle extras) {
- // TODO Auto-generated method stub
- }
- //gps ,打开
- public void onProviderEnabled(String provider) {
- // TODO Auto-generated method stub
- }
- //关闭
- public void onProviderDisabled(String provider) {
- // TODO Auto-generated method stub
- }
- }
- /**
- * 获取手机的最后一次位置
- * @return
- */
- public String getLastPosition(){
- return sp.getString("lastlocation", "");
- }
- }
获取短信的经纬度并将获取到的经纬度发送到指定的号码上:
- //获取当前手机的经纬度.
- GPSInfoService.getInstance(context).registerLocationUpdates();
- //把经纬度的信息发送到安全号码 ,获取到短信发送器,将短信发送到指定的号码
- SmsManager smsManager = SmsManager.getDefault();
- smsManager.sendTextMessage("15287978798", null, GPSInfoService.getInstance(context).getLastPosition() , null, null);
评论暂时关闭