2013-09-28 38 views
0

我试图让我的GPS在一个服务工作,但它不工作。 GPS位自身工作,但不在服务中。Android GPS不能在服务

我曾尝试用System.out.println()进行调试,并且喜欢它停止工作的位置,但无法找出为什么它看起来不错。

public int onStartCommand(Intent intent, int flags, int startId) { 

     System.out.println("test 1"); 
     LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 

     System.out.println("test 2"); 
     LocationListener lli = new myLocationListener(); 
     System.out.println("test 3"); 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, lli); 

     System.out.println("test 4"); 



     // We want this service to continue running until it is explicitly 
     // stopped, so return sticky. 
     return START_STICKY; 
    } 

class myLocationListener implements LocationListener{ 



    @Override 
    public void onLocationChanged(Location location) { 
     // TODO Auto-generated method stub 

     if(location != null){ 

      pet.setMeter(); 


     } 

    } 

它进入测试4,然后死亡。我迷失在为什么如果任何人都可以帮助这将是非常感谢。

回答