android判断GPS是否开启

判断手机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);
}
}

参考链接:http://blog.csdn.net/jkguang/archive/2011/04/07/6307523.aspx


--------------------------------------------------------


private void initGPS(){
LocationManager locationManager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

//判断GPS模块是否开启,如果没有则开启
if(!locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)){
Toast.makeText(this, "GPS is not open,Please open it!", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivityForResult(intent,0);
}
else {
Toast.makeText(this, "GPS is ready", Toast.LENGTH_SHORT);
}
}

参考链接:http://hi.baidu.com/yimifeitian/blog/item/ed6a92d7fe19783906088b04.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值