判断手机GPS是否开启
下边这小段代码是用来判断手机的GPS服务是否为开启状态.如果是就提示用户GPS已经打开.
如果现在GPS 处于关闭状态,那么给用户一个提示, 然后打开GPS设置界面,让用户更改GPS为启动状态.
JAVA代码:
private void openGPSSettings()
{
LocationManager alm =
(LocationManager)this.getSystemService( Context.LOCATION_SERVICE );
if( alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER ) )
{
Toast.makeText( this, “GPS is already on”, Toast.LENGTH_SHORT ).show();
}
else
{
Toast.makeText( this, “Please turn on GPS”, Toast.LENGTH_SHORT ).show();
Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS );
startActivity(myIntent);
}
}