【问题标题】:how to hide the gps icon on status bar when the service stops?服务停止时如何隐藏状态栏上的gps图标?
【发布时间】:2012-05-31 14:33:38
【问题描述】:

当我的服务被禁用时,我需要从状态栏中隐藏 GPS 图标。

在我的应用程序中,我有两个菜单选项,当我按下“启用”时,gps 图标必须显示在状态栏上,当我按下“禁用”时,gps 图标不应显示在状态栏上。

【问题讨论】:

  • 谢谢你。我已经这样做了,但我不想通过设置禁用 gps。我想在按下“禁用”菜单项时通过编程禁用它。
  • 如果您要问的是如何在 GPS 仍然处于活动状态时隐藏 GPS 图标,那么不,您不能这样做。你也不应该。

标签: android


【解决方案1】:

如果您通过LocationManager请求GPS更新,您可以使用此功能删除更新(禁用GPS):

locationManager.removeUpdates(this);

【讨论】:

    【解决方案2】:

    要在服务停止时隐藏 GPS 图标,您需要删除当前活动的位置更新注册。

    您可以通过调用位置管理器上的removeUpdates(PendingIntent intent) 来完成此操作。

    removeUpdates(PendingIntent intent)
    Removes any current registration for location updates of the current activity with the given PendingIntent.
    

    看看这个Link

    【讨论】:

      【解决方案3】:

      您只需禁用 GPS 设备即可。当您禁用 GPS 时,图标将从系统托盘中消失。

      Check this question for the answer.

      【讨论】:

      • 我可以在服务类的onDestroy方法中这样写代码吗
      • 像 public void onDestroy() { super.onDestroy(); mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); mlocListener = new MyLocationListener(); ((LocationManager) mlocListener).removeUpdates((LocationListener) this); Log.v("销毁","销毁"); Intent it=new Intent(NewThread.this,LanLatActivity.class);开始活动(它);标志=假; }
      • 停止 GPS 并显示应用程序主页(LanLatActivity)。当我单击“禁用”菜单项时,应用程序将在此处终止。请帮助我。对我来说这是一项紧迫的任务。
      • 我也尝试过另一种方式。下面的代码 public void onDestroy() { super.onDestroy(); ((LocationManager) mlocListener).removeUpdates((LocationListener) this);标志=假;
      【解决方案4】:

      简单。当你想要这个图标时,启用 GPS,当你不想要它时,禁用 GPS。

      【讨论】:

      • 非常感谢。如果我有任何疑问,我会问你,因为我是这项技术的新手。我从 2 周开始就致力于此。
      猜你喜欢
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      • 1970-01-01
      相关资源
      最近更新 更多