如何阻止;搜索全球定位系统“;在android中

如何阻止;搜索全球定位系统“;在android中,android,gps,Android,Gps,我正在尝试停止应用程序中的“搜索GPS”。 当我使用这行代码时: this.locationManager.removeUpdates(this); 我仍然可以在通知栏中看到GPS的图标,它根本不会停止。 我还能做什么? 谢谢 您应该像这样将location Listener实例传递给removeUpdate方法,而不是传递它 locationManager.removeUpdates(gpsLocationListener); 在哪里 GPSLocationListener gpsLoca

我正在尝试停止应用程序中的“搜索GPS”。 当我使用这行代码时:

this.locationManager.removeUpdates(this);
我仍然可以在通知栏中看到GPS的图标,它根本不会停止。 我还能做什么?
谢谢

您应该像这样将location Listener实例传递给removeUpdate方法,而不是传递它

locationManager.removeUpdates(gpsLocationListener);
在哪里

GPSLocationListener gpsLocationListener = new GPSLocationListener();

class GPSOnChangeLocationListener implements LocationListener {
           public void onLocationChanged(Location location) {}
           public void onProviderDisabled(String arg0) {}
           public void onProviderEnabled(String arg0) {}
           public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
}

您应该像这样将location Listener实例传递给removeUpdate方法,而不是传递它

locationManager.removeUpdates(gpsLocationListener);
在哪里

GPSLocationListener gpsLocationListener = new GPSLocationListener();

class GPSOnChangeLocationListener implements LocationListener {
           public void onLocationChanged(Location location) {}
           public void onProviderDisabled(String arg0) {}
           public void onProviderEnabled(String arg0) {}
           public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
}

尝试
locationManager.removeUpdates(gpsl)

尝试
locationManager.RemoveUpdate(gpsl)

我想出来了。 这就是我所做的,它是有效的:

private void registerLocationUpdates() {
    Intent intent = new Intent(ParkOGuardActivity.class.getName()
            + ".LOCATION_READY");
    pendingIntent = PendingIntent.getBroadcast(
            getApplicationContext(), 0, intent, 0);
    // minimum every 30 minutes, 300 kilometers 
    this.locationManager.requestLocationUpdates(this.provider, 30000,
            300000, pendingIntent);
}

private void cancelLocationUpdates() {
    this.locationManager.removeUpdates(pendingIntent);
}
多亏了你们所有人的帮助。

我终于明白了。 这就是我所做的,它是有效的:

private void registerLocationUpdates() {
    Intent intent = new Intent(ParkOGuardActivity.class.getName()
            + ".LOCATION_READY");
    pendingIntent = PendingIntent.getBroadcast(
            getApplicationContext(), 0, intent, 0);
    // minimum every 30 minutes, 300 kilometers 
    this.locationManager.requestLocationUpdates(this.provider, 30000,
            300000, pendingIntent);
}

private void cancelLocationUpdates() {
    this.locationManager.removeUpdates(pendingIntent);
}

感谢你们所有试图帮助我的人。

我不知道是谁干的。。。我还没试过。我有点新。。。所以我不知道我该怎么做。。我的应用程序在实现LocatinListner的类中…这很难,因为有很多代码。。。我会尽力解释我的工作。主要活动是实现LoactionListner<代码>私有无效注册表位置更新(){Intent Intent Intent=new Intent(ParkOGuardActivity.class.getName()+“.LOCATION_READY”);PendingIntent PendingIntent=PendingIntent.getBroadcast(getApplicationContext(),0,Intent,0);//此.locationManager.requestLocationUpdates至少每30分钟300公里一次(this.provider,300000,pendingent);}private void cancelocationupdates(){locationManager.removeUpdates(this);}
我不知道是谁干的……我还没试过。我是一个新手……所以我不知道怎么做……我的应用程序在实现LocatinListner的类中……这很难,因为有很多代码……我会试着解释我做了什么。主要活动是实现LoactionListner。
private void registerLocationUpdates(){Intent Intent Intent=new Intent(ParkOGuardActivity.class.getName()+“.LOCATION_READY”);pendingent pendingent=pendingent.getBroadcast(getApplicationContext(),0,Intent,0);//此.locationManager.requestLocationUpdates(this.provider,300000,300000,pendingent)至少每30分钟一次;}private void cancelLocationUpdates(){locationManager.removeUpdates(this);}
感谢您共享解决方案。请随时在此处将您自己的答案标记为已接受(时间到时),。通过这种方式,回答问题的搜索引擎用户可以很清楚地为您解决问题,他们不会浪费时间去理解一个可能对他们根本没有帮助的答案。感谢您分享解决方案。请随时在此处将您自己的答案标记为已接受(时间到了时)通过这种方式,搜索引擎用户很清楚,他们的答案为你解决了问题,他们不会浪费时间去理解一个可能对他们根本没有帮助的答案。