2011-08-09 15 views
2

サービスがバックグラウンドで実行されているときにユーザーが画面に触れると検出する方法を見つけようとしています。たとえば、ユーザーがホーム画面のアプリアイコンを押したときを検出できるようにしたいとします。これは可能なのですか?もしそうなら、どのように実装されますか?Android:サービスからの接触を検出する

+0

便利になるかもしれません:[サービスからのタッチを検出](http://stackoverflow.com/questions/4481226/creating-a-システムオーバレイ - 常にトップ - オン - ボタン - アンドロイド) –

答えて

1

thisサービスの説明を参照してください。メッセンジャーを使用してサービスにメッセージを送信できるはずです。だからあなたのonClickイベントで、あなたのメッセンジャー...例を呼び出します。

 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. 
     } 
関連する問題