2016-06-10 53 views
-1

我正在開發一個應用程序,其中僅使用GPS提供程序跟蹤用戶的位置(僅位置的設備模式)。因此,如果用戶使用Wifi和數據將他的位置優先級設置爲近似位置,則應用程序將無法按預期工作。因此,我需要通過編程方式檢查用戶對位置模式(高精度,大概位置或設備)的選擇並顯示適當的對話框。什麼將是一個乾淨的方式來實現這一目標?如何以編程方式找出打開哪種模式的位置?

+0

看看答案在這裏:http://stackoverflow.com/questions/30467850/monitoring-geofences-after-user-turns-location-service-off-and-on/30580898 –

+0

@DanielNugent我不想像廣播接收機那樣重量輕。我覺得凱倫的答案是要走的路。讓我檢查一下。 –

+0

鏈接的答案有你需要的代碼,但也有很多其他的東西。我只是在這裏發佈了一個答案,只有你需要的代碼.... –

回答

0

1,要檢查提供商模式(GPS,網絡,窖-ID)

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 
//get currently used providers 
locationManager.getProviders(true); 

2,顯示對話框

new AlertDialog.Builder(this). 
setTitle("Title"). 
setMessage("content"). 
show(); 
0

請注意,您的應用程序將兩個GPS只工作模式也是高精度模式,因爲兩種設置均啓用GPS。

爲了檢查GPS是否啓用,這將做到這一點。

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 

if (!isGpsEnabled) { 
    //show your alert here 
}