這裏是下面的一個代碼假設監聽GPS的更新和發送通知給主要活動Android GPS。位置監聽器並不想獲得一個修復:(
但是它似乎並不奏效:)
無錯誤,只有onLocationChanged不被調用!
有趣的是:當我運行一些其他應用程序來獲得GPS修復,然後開始我的應用程序=> onLocationChanged被調用,只有準確性降級,並最終修復丟失。
我也嘗試添加到此代碼GPS偵聽器=>它的工作原理,視圖中的衛星每秒鐘都報告,只有修復從未被指責。
這到底是怎麼回事? :)
公共類PhoneGPSpos {
private Handler myHandler = null;
private LocationManager lm;
private LocationListener locationListener;
private Location currentBest;
Context m_context;
公共PhoneGPSpos(上下文的背景下,處理程序處理){
myHandler = handler;
m_context = context;
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Bundle bundle = new Bundle();
// boolean xtraInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_xtra_injection",bundle);
// boolean timeInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_time_injection",bundle);
currentBest = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
locationListener = new LocationListener()
{
public void onLocationChanged(Location location)
{
Log.w("Compass", "Loc");
if (location != null)
{
currentBest = location;
Message msg = new Message();
msg.arg1 = 5;
myHandler.sendMessage(msg);
}
}
public void onStatusChanged(String provider, int status, Bundle
extras) {
Log.d("Compass", "Stat");
}
public void onProviderEnabled(String provider) {
Log.d("Compass", "Prov e");
}
public void onProviderDisabled(String provider) {
Log.d("Compass", "Prov d");
}
};
}
public void requestGPS()
{
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Log.d("Compass", "gps requested");
}
public void stopGPS()
{
Log.d("Compass", "gps stopped");
lm.removeUpdates(locationListener);
}
public synchronized Location getBest()
{
return currentBest;
}
}
你在哪裏檢測?在室內? – Ian
不是。正如我所說:「其他應用程序能夠修復」。當我切換回到我的應用程序剛纔onLocationChanged被稱爲只有準確性正在退化。並且修復最終會丟失 – user929298