[英]Android GPS on or off state
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. 有没有办法检查Android GPS是否在没有任何许可的情况下打开或关闭,只是我不需要切换它的状态。
Thanks 谢谢
No. Checking GPS Status on Android requires 在Android上检查GPS状态需要
android.permission.ACCESS_FINE_LOCATION
The code to check the status of GPS 用于检查GPS状态的代码
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
steps - 脚步 -
You require following permission in Manifest file too - 您在Manifest文件中也需要以下权限 -
android.permission.ACCESS_FINE_LOCATION
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
Or simply you can check 或者只是你可以检查
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE ); boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
run your services continuous to monitor connection 持续运行您的服务以监控连接
If you want to check the condition of GPS that whether it is ON or OFF, then this solution will help you 如果您想检查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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.