---
title: "android 检查GPS是否开启，打开GPS设置界面"
author: "xinanadu"
date: "2012-10-07T12:44:28Z"
tags: []
categories: ["移动开发"]
slug: "android-gps-gps"
draft: false
lastmod: "2012-10-07T12:45:02Z"
id: 1692168
url: "https://zhegui.iteye.com/blog/1692168"
---

转自[http://iriverman.iteye.com/blog/807965](http://iriverman.iteye.com/blog/807965)

 

```
GPS是否开启
LocationManager locationManager = (LocationManager)getContext().
getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);


进入GPS设置页面
        Intent intent = new Intent();
        intent.setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try 
        {
            getContext().startActivity(intent);
                    
            
        } catch(ActivityNotFoundException ex) 
        {
            
            // The Android SDK doc says that the location settings activity
            // may not be found. In that case show the general settings.
            
            // General settings activity
            intent.setAction(Settings.ACTION_SETTINGS);
            try {
                   getContext().startActivity(intent);
            } catch (Exception e) {
            }
        }
```