首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android判断GPS是不是开启

2012-09-13 
android判断GPS是否开启判断手机GPS是否开启下边这小段代码是用来判断手机的GPS服务是否为开启状态.如果是

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

热点排行