2011-08-09 7 views
2

백그라운드에서 서비스가 실행되는 동안 사용자가 어떤 방식 으로든 화면을 터치 할 때 감지하는 방법을 찾으려고합니다. 예를 들어 사용자가 홈 화면에서 앱 아이콘을 누를 때이를 감지 할 수 있기를 원합니다. 이것이 가능한가? 그렇다면 어떻게 구현 될 것인가?Android : 서비스에서 터치 감지

+0

가 편리하게 할 수 있음 : 그래서 당신의 onClick 이벤트에 당신은 ... 예를 들어 메신저 호출 (http://stackoverflow.com/questions/4481226/creating-a- [서비스에서 접촉을 감지] 시스템 오버레이 - 항상 맨 위 버튼 안드로이드) –

답변

1

서비스에 대한 설명은 this을 참조하십시오. Messenger를 사용하여 서비스에 메시지를 보낼 수 있어야합니다.

 try { 
      Message msg = Message.obtain(null, 
        MessengerService.MSG_BUTTON_CLICKED); 
      msg.replyTo = mMessenger; 
      mService.send(msg); 

      // Give it some value as an example. 
      msg = Message.obtain(null, 
        MessengerService.MSG_SET_VALUE, this.hashCode(), 0); 
      mService.send(msg); 
     } catch (RemoteException e) { 
      // In this case the service has crashed before we could even 
      // do anything with it; we can count on soon being 
      // disconnected (and then reconnected if it can be restarted) 
      // so there is no need to do anything here. 
     }