2011-01-21 87 views
1

有人可以告訴我在代碼中注意哪裏檢查GPS是否啓用或禁用?瀏覽器崩潰,如果我建立沒有GPS的android

我的瀏覽器崩潰,如果我建立沒有GPS(自定義之一)的android。當我嘗試打開試圖獲取位置的網頁時(例如在Google主頁中),就會發生這種情況。

在此先感謝。

+1

據我知道,GPS是爲Android平臺的要求之一。我想你需要製造一些僞造的模塊,作爲一個虛假的GPS。 – 2011-01-21 06:32:18

回答

0
String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); 
if(provider != null){  
     if(! provider.contains("gps")){  
       //GPS is disabled..prompt the user to enable GPS... 
       //you can also start an intent to send the user to the settings page.. 
       Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
        startActivityForResult(intent, 5); 
      } 

} 

使用onActivityResult,看看用戶是否啓用GPS ...