有没有任何方法可以在不需要任何权限的情况下检查Android GPS是否开启或关闭,只是状态而不需要切换它。
谢谢
有没有任何方法可以在不需要任何权限的情况下检查Android GPS是否开启或关闭,只是状态而不需要切换它。
谢谢
不需要。在Android上检查GPS状态不需要
android.permission.ACCESS_FINE_LOCATION
检查GPS状态的代码
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
boolean statusOfGPS = manager.isProviderEnabled(LocationManager.GPS_PROVIDER);
步骤 -
You require following permission in Manifest file too -
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
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();