2012-04-10 2 views
1

나는 cwac-Location Poller (here)를 사용하여 지속적으로 사용자 위치를 폴링하고 위치 기반 알림을 표시합니다. 이 모든 것은 잘 작동하지만 현재 다른 BroadcastReceiver을 첨부하려고합니다. 그래서 내 애플리케이션이 포 그라운드에있는 경우 알림을 현재 사용자 위치에 애니메이션으로 표시하는 대신 표시되도록합니다. 그러나 웬일인지 나는 그것을 작동시킬 수 없다.LocationPoller 및 여러 개의 브로드 캐스트 수신기

onCreate() 내가 폴러 시작하는 코드를 다음 한 MapActivity 방법 :

@Override 
public void onCreate(Bundle savedInstanceState) { 
    ..... 

    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); 

    Intent i = new Intent(this, LocationPoller.class); 

    Bundle bundle = new Bundle(); 
    LocationPollerParameter parameter = new LocationPollerParameter(bundle); 
    parameter.setIntentToBroadcastOnCompletion(new Intent(this, LocationReceiver.class)); 
    parameter.setProviders(new String[] {LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER}); 
    parameter.setTimeout(60000); 
    i.putExtras(bundle); 

    pendingIntent = PendingIntent.getBroadcast(this, 0, i, 0); 

    alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
       SystemClock.elapsedRealtime(), PERIOD, pendingIntent);         
} 

내가 registerReceiver() 방법을 사용하여 다른 수신기를 등록하고 방법 onResume()에서 :

: locationReceiver의 모습

@Override 
protected void onResume() { 
    super.onResume(); 
    IntentFilter intentFilter = new IntentFilter(com.commonsware.cwac.locpoll.LocationPollerParameter.INTENT_TO_BROADCAST_ON_COMPLETION_KEY); 
    intentFilter.setPriority(1); 
    registerReceiver(locationReceiver, intentFilter); 
} 

private BroadcastReceiver locationReceiver = new BroadcastReceiver() {  
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d(TAG, "mapActivity called"); 
     abortBroadcast(); 
    } 
}; 
(210)

그리고 순서는 내가 대신 이제 문제는 내 동적으로 등록 된 수신기가 호출되지 얻을 않습니다 만의 AndroidManifest.xml에서 언급 한 수행 sendBroadcast

public void onLocationChanged(Location location) { 
     handler.removeCallbacks(onTimeout); 
     Intent toBroadcast = createIntentToBroadcastOnCompletion(); 

     toBroadcast.putExtra(LocationPollerResult.LOCATION_KEY, location);   
     sendOrderedBroadcast(toBroadcast, null); 
     quit(); 
} 

sendOrderedBroadcast를 사용하는 LocationPollerService을 수정 한 다수의 수신기에 방송 주문한 보내려면

<receiver android:name=".receiver.LocationReceiver" /> 
    <receiver android:name="com.commonsware.cwac.locpoll.LocationPoller" /> 
    <service android:name="com.commonsware.cwac.locpoll.LocationPollerService" /> 

답변

2

귀하의 문제는 IntentFilter 자바와에서 만든 사이의 분리에구현, 귀하의 질문에 포함되지 않은. IntentFilter에 특정 작업 문자열이있는 브로드 캐스트가 예상됩니다. Intent에 생성중인 createIntentToBroadcastOnCompletion()에는 분명히이 작업 문자열이 포함되어 있지 않습니다.

BTW, "및 여러 수신자에게 브로드 캐스트 보내기"와 관련하여 sendBroadcast()은 여러 수신자에게 브로드 캐스트를 완벽하게 전송할 수 있습니다.

+0

다음은 createIntentToBroadcastOnCompletion() {새로운 인 텐트 (locationPollerParameter.getIntentToBroadcastOnCompletion())을 반환합니다. } getIntentToBroadcastOnCompletion()은 "com.commonsware.cwac.locpoll.EXTRA_INTENT"와 정확히 같은 문자열을 반환합니다. – Waqas

+0

@Waqas : com.commonsware.cwac.locpoll.EXTRA_INTENT는 com.commonsware와 같지 않습니다. .cwac.locpoll.LocationPollerParameter.INTENT_TO_BROADCAST_ON_COMPLETION_KEY'. – CommonsWare

+0

빠른 답장을 보내 주셔서 감사합니다. com.commonsware.cwac.locpoll.LocationPollerParameter.INTENT_TO_BROADCAST_ON_COM PLETION_KEY는 com.commonsware.cwac.locpoll.EXTRA_INTENT 값이있는 정적 문자열입니다. – Waqas

관련 문제