Android获取系统隐藏服务实现锁屏


获取手机经纬度有 gps , network  , 基站 三种方式,我们可以根据定位的条件,获取一个最好的定位方式。然后将获取到经纬度信息发送到指定的手机号码中。

  1. /* 
  2.  * 单态只允许存在一个实例. 
  3.  * 获取手机的gps信息  
  4.  */  
  5. public class GPSInfoService {  
  6.     private Context context;  
  7.     private LocationManager manager;  
  8.     SharedPreferences sp ;  
  9.     //私有化构造方法    
  10.     private  GPSInfoService(Context context){     
  11.         this.context= context;  
  12.         manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);  
  13.         sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);  
  14.     }  
  15.     private static GPSInfoService mGPSService;  
  16.       
  17.     public synchronized static GPSInfoService getInstance(Context context){  
  18.         if(mGPSService==null)  
  19.             mGPSService = new GPSInfoService(context);  
  20.         return mGPSService;  
  21.     }  
  22.       
  23.     /* 
  24.      *  当前你的手机 所支持的定位方式获取出来  
  25.      *  有多种定位方式 gps network ,基站, passive 
  26.      *  可以根据定位的条件 ,获取 一个最好的定位方式http://www.bkjia.com  
  27.      */  
  28.     public void registerLocationUpdates(){  
  29.         Criteria criteria = new Criteria();  
  30.         // 设置定位的精度    
  31.         criteria.setAccuracy(Criteria.ACCURACY_COARSE); //获取大体的位置   
  32.         criteria.setAltitudeRequired(false); // 海拔信息   
  33.         criteria.setCostAllowed(true); //允许产生费用   
  34.         criteria.setPowerRequirement(Criteria.POWER_LOW); //低功耗   
  35.           
  36.         //获取一个最符合查询条件的位置提供者    
  37.         String provider  =manager.getBestProvider(criteria, true);  
  38.           
  39.         // 位置改变就会调用Linster的监听器 获取经度纬度   
  40.         manager.requestLocationUpdates(provider, 600000, getLinster());  
  41.     }  
  42.       
  43.     public void cancleLocationUpdates(){  
  44.         manager.removeUpdates(getLinster());  
  45.     }  
  46.     private static MyGPSLinster myGPSLinser;  
  47.       
  48.     private MyGPSLinster getLinster(){  
  49.         if(myGPSLinser==null)  
  50.             myGPSLinser = new MyGPSLinster();  
  51.         return myGPSLinser;  
  52.     }  
  53.       
  54.     private class MyGPSLinster implements LocationListener{  
  55.   
  56.         // 用户位置改变的时候 的回调方法    
  57.         public void onLocationChanged(Location location) {  
  58.             //获取到用户的纬度    
  59.             double latitude= location.getLatitude();  
  60.             //获取到用户的经度   
  61.             double longitude = location.getLongitude();  
  62.             //进行封装写入到文件中   
  63.             String locationstr = "jing du "+ longitude + " weidu  :"+latitude;  
  64.             Editor  editor =  sp.edit();  
  65.             editor.putString("lastlocation", locationstr);  
  66.             editor.commit();  
  67.         }  
  68.         // 状态改变    
  69.         public void onStatusChanged(String provider, int status, Bundle extras) {  
  70.             // TODO Auto-generated method stub   
  71.         }  
  72.         //gps ,打开   
  73.         public void onProviderEnabled(String provider) {  
  74.             // TODO Auto-generated method stub   
  75.         }  
  76.         //关闭   
  77.         public void onProviderDisabled(String provider) {  
  78.             // TODO Auto-generated method stub   
  79.         }  
  80.     }  
  81.       
  82.     /** 
  83.      * 获取手机的最后一次位置  
  84.      * @return 
  85.      */  
  86.     public String getLastPosition(){  
  87.         return sp.getString("lastlocation""");  
  88.     }  
  89. }  

获取短信的经纬度并将获取到的经纬度发送到指定的号码上:

  1. //获取当前手机的经纬度.   
  2. GPSInfoService.getInstance(context).registerLocationUpdates();  
  3. //把经纬度的信息发送到安全号码 ,获取到短信发送器,将短信发送到指定的号码   
  4. SmsManager smsManager = SmsManager.getDefault();  
  5. smsManager.sendTextMessage("15287978798"null, GPSInfoService.getInstance(context).getLastPosition() , nullnull);  

相关内容