2012-11-15 76 views
2

當我試圖讓我的位置在三星Galaxy S3上時,我的應用程序崩潰。它可以在我測試過的其他三款手機上使用。我只在三星Galaxy S3上有遠程測試人員,所以我不能得到錯誤信息。這裏是我的代碼:android getlastknown位置在三星Galaxy S3 s3崩潰

Location finalLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    locationManager.removeUpdates(locationListenerGps); 
    locationManager.removeUpdates(locationListenerNetwork); 

    Location net_loc=null, gps_loc=null; 
    if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) 
     gps_loc=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
    if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) 
     net_loc=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

    //if there are both values use the latest one 
    if(gps_loc!=null && net_loc!=null){ 
     if(gps_loc.getTime()>net_loc.getTime()) 
      finalLocation = gps_loc; 
     else 
      finalLocation = net_loc; 
    } 

    if(gps_loc!=null){ 
     finalLocation = gps_loc; 

    } 
    if(net_loc!=null){ 
     finalLocation = net_loc; 

    } 
+0

讓他們安裝一個logcat的應用程序,讓你的崩潰日誌... – dymmeh

+0

是的,我會努力的!謝謝 – user1828049

+0

Android應用程序不使用Google Maps API V3。 (標籤替換) – Marcelo

回答

1

我認爲這是一個「功能」與4.0.4版本,檢查(getLastKnownLocation does not work on Samsung Galaxy S3 4.0.4)

我有同樣的問題,當我升級到4.1時,它消失了。

您可能必須抓住兩者都爲空的情況,我發現PASSIVE_PROVIDER的作品。

if (gps_loc == null && net_loc == null) { // only S3 gets this.... 
     finalLocation= locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); 
    } 
    if (finalLocation == null) panic.... 
0

這是很難說確切的問題,而一個logcat的,但getLastKnownLocation可以返回在某些情況下(不太可能,但可能的)空。如果是這種情況,很容易看到會導致崩潰。也許可以嘗試添加一些代碼來檢查getLastKnownLocation是否返回值,如果不是,則使用虛擬值或「暫停」您的操作並自行獲取位置。

http://developer.android.com/reference/android/location/LocationManager.html#getLastKnownLocation(java.lang.String

相關問題