2011-06-28 51 views
1

通過LocationManager.KEY_PROXIMITY_ENTERING不可用於接近警報?

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
Intent intent = new Intent(Constants.ACTION_PROXIMITY_ALERT); 
intent.putExtra(Constants.INTENT_EXTRA_LOCATION, location); // custom payload 
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0); 

locationManager.addProximityAlert(location.getLatitude(), 
    location.getLongitude(), location.getRadius(), -1, pendingIntent); 

對於一個給定的座標接近警報註冊後我得到進入或離開配置的位置時提供給我的服務的意圖。到現在爲止還挺好。

不幸的是,這些傳送的意向都沒有攜帶標識位置變化類型(進入或退出)的布爾額外LocationManager.KEY_PROXIMITY_ENTERING,可通過Intent.getBooleanExtra檢索。我的觀察是基於AOSP 2.1和AOSP 2.2。根據documentation,此額外應始終存在。

有什麼我錯過了?在模擬器上使用模擬位置運行時,是否存在這種額外限制?

回答

5

事實證明,這似乎是由於在PendingIntent中添加了額外的可序列化額外引起的。作爲一種解決方法,如果需要額外的有效載荷,可以自行執行序列化或僅存儲基元類型或字符串。

+0

問題似乎仍然存在,因爲4.1.2 ...(facepalm)只是想知道,有人會解決這個問題嗎? –

+0

@deville如果你想看到這個問題,你應該在https://code.google.com/p/android/issues/list上提出一個錯誤問題。 –