Android GPS 开启或关闭状态

发布于 2024-10-04 20:57:44 字数 68 浏览 0 评论 0原文

有没有办法在没有任何许可的情况下检查Android GPS是否打开或关闭,只是我不需要切换它的状态。

谢谢

Is there any way to check if the Android GPS is on or off without any permission, just the state I don't need to toggle it.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾冷 2024-10-11 20:57:44

否。在 Android 上检查 GPS 状态需要

android.permission.ACCESS_FINE_LOCATION

检查 GPS 状态的代码


 LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
 boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);

No. Checking GPS Status on Android requires

android.permission.ACCESS_FINE_LOCATION

The code to check the status of GPS


 LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
 boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);

没有伤那来痛 2024-10-11 20:57:44

步骤 -

  1. 创建在后台运行的服务
  2. 您也需要清单文件中的以下权限 -

    android.permission.ACCESS_FINE_LOCATION
    
  3. 编写代码

     最终 LocationManager manager = (LocationManager)context.getSystemService (Context.LOCATION_SERVICE );
    
    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
    
    //你想做什么
     别的
    
       //你想做什么
    
  4. 或者简单地您可以检查

    LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
    boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    
  5. 连续运行您的服务以监视连接

  6. 从 Activity 调用您的服务

steps -

  1. Create services running in backgroud
  2. You require following permission in Manifest file too -

    android.permission.ACCESS_FINE_LOCATION
    
  3. write code

     final LocationManager manager = (LocationManager)context.getSystemService    (Context.LOCATION_SERVICE );
    
    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
    
    //what you want to do
     else
    
       //what you want to do
    
  4. Or simply you can check

    LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
    boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    
  5. run your services continuous to monitor connection

  6. call your services from Activity
我还不会笑 2024-10-11 20:57:44

如果您想检查 GPS 的状态,无论是打开还是关闭,那么这个解决方案将帮助您

final LocationManager manager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE );

if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
  Toast.makeText(context, "GPS is disable!", Toast.LENGTH_LONG).show(); 
else
 Toast.makeText(context, "GPS is Enable!", Toast.LENGTH_LONG).show();

If you want to check the condition of GPS that whether it is ON or OFF, then this solution will help you

final LocationManager manager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE );

if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) )
  Toast.makeText(context, "GPS is disable!", Toast.LENGTH_LONG).show(); 
else
 Toast.makeText(context, "GPS is Enable!", Toast.LENGTH_LONG).show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文