2013-12-15 4 views
1

제 질문에 대한 답변을 찾고 있는데 어디서나 찾을 수 없습니다.AccesibilityService와 Activity 간의 통신

AccesibilityService가 실행 중이고 MainActivity로 정보를 보내려고합니다.

나는 메신저 클래스로 해보려고했지만 나는 할 수 없다.

누구든지 도와 줄 수 있습니까?

은 내가 mainactivity에이 코드를 넣어 가지고 :

class IncomingHandler extends Handler { 
    @Override 
    public void handleMessage(Message msg) { 
     switch (msg.what) { 
     case NoficationService.MSG_ENCENDER: 
      // Envía "1". 
      String message = "1"; 
      mApp1.sendData(message); 
      break; 
     default: 
      super.handleMessage(msg); 
     } 
    } 
} 

을 MainActivity에서이 코드가 : 당신의 도움을 기다리는

try { 
      Message msg = Message.obtain(null, NoficationService.MSG_ENCENDER, 0, 0); 
      msg.replyTo = mMessenger; 
      mService.send(msg); 
      Log.d(tag, "Enviado Msg"); 
     } catch (RemoteException e) { 
      Log.d(tag, "Excepción Msg"); 
     } 

합니다. 미리 감사드립니다.

답변

0

에 한번 사용 방송 :

public final static String BROADCAST_ACTION = "com.packegeName"; 

1) 활동에 브로드 캐스트를 등록 :

BroadcastReceiver br = new BroadcastReceiver() { 

public void onReceive(Context context, Intent intent) { 
     // proccess messages 
} 
} 


IntentFilter intFilt = new IntentFilter(BROADCAST_ACTION); 
registerReceiver(br, intFilt); 

2) AccesibilityService

그것은 작동
Intent intent = new Intent(MainActivity.BROADCAST_ACTION); 
intent.putExtra(MainActivity.PARAM_STATUS, MainActivity.STATUS_FINISH); 
intent.putExtra(MainActivity.PARAM_RESULT, time * 100); 
sendBroadcast(intent); 
+1

에서 방송을 보냅니다. 정말 고맙습니다! – ChristLarsen