2011-04-07 38 views
0

我使用地圖創建應用程序。關閉wi -fi的錯誤消息

它的工作原理,但是當沒有互聯網或WiFi的應用程序崩潰。

而不是崩潰我想在設備中顯示錯誤消息。

它不顯示在logcat中。

這裏是我的代碼:

LocationManager myManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
if(myManager != null){ 
    String param=(String)myManager.getProviders(true).get(0); 
    Location loc = myManager.getLastKnownLocation(param); 

    if(loc != null){ 
     ............ 
    } else { 
     Log.e("AndroidMaps-1 ","Error: Location is null"); 
     builder.setMessage("err").setPositiveButton("Yes",dialogClickListener).show(); 
    } 
} else { 
    Log.e("AndroidMaps-2 ","Error: Location Manager is null"); 
    builder.setMessage("Are you sure").setPositiveButton("Yes",dialogClickListener).show(); 
} 

Wi-Fi功能被關閉,我不得到的logcat或對話框中的錯誤信息。

+0

爲什麼不使用gps? – Ian 2011-04-07 14:50:28

回答

1

在做其他事情之前,您可以檢查互聯網連接。如果沒有互聯網連接可用,您可以通知用戶。

雖然在我的應用程序中,當Map試圖在沒有任何Internet連接的情況下嘗試引導切片時,它不會崩潰。