2014-06-19 23 views
2

我與Android Geofence Api混淆。所以該方法說.setTransitionTypes(int)。但是,當我嘗試設置地理圍欄來監視特定地理圍欄的進入和退出時,它只會監視我設置爲監視的Transition的過渡類型。地理柵欄與多個轉換類型設置 - Android

這裏是

public Geofence toGeofence() { 
// Build a new Geofence object 
return new Geofence.Builder() 
     .setRequestId(getId()) 
     .setTransitionTypes(getTransitionType()) //Geofence.GEOFENCE_TRANSITION_ENTER 
     .setTransitionTypes(getTransitionType2())// Geofence.GEOFENCE_TRANSITION_EXIT 
     .setCircularRegion(
       getLatitude(), getLongitude(), getRadius()) 
     .setExpirationDuration(mExpirationDuration) 
     .build();} 

這僅監視最後過渡型組其是出口過渡,我已經使出創建2個地理圍欄對於相同的區域,一個監視每個過渡的我的代碼的一個例子,但我覺得這是不行的路。任何幫助?

回答

6

對於那些可能遇到此問題的人來說,設置多種轉換類型的方法是通過添加|在每個過渡類型之間。

geofence.setTransitionType(getTransitionType() | getTransitionType2());