2013-07-12 3 views
0
문제가 내 안드로이드 응용 프로그램은 RemObjects에-이벤트를 수신 만드는 데

... Android에서 RemObjects 이벤트를받는 방법?

여기에 안드로이드 (자바) 클래스의

: 나는 서버에서 이벤트에 가입하고있어 어떻게 여기

package no.wolftech.fieldagentforandroid.tools; 

import java.net.URI; 
import java.util.Date; 

import no.wolftech.fieldagentforandroid.AndroidService_AsyncProxy; 
import no.wolftech.fieldagentforandroid.FieldAgent; 
import no.wolftech.fieldagentforandroid.MonitorService; 
import no.wolftech.fieldagentforandroid.OnIdleReportDeliveredEvent; 
import no.wolftech.fieldagentforandroid.R; 
import no.wolftech.fieldagentforandroid.ROEventsAdapter; 
import no.wolftech.fieldagentforandroid.ReportStruct; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Handler; 
import android.util.Log; 

import com.remobjects.sdk.AsyncRequest; 
import com.remobjects.sdk.ClientChannel; 
import com.remobjects.sdk.ClientChannel.IClientChannelCallback; 
import com.remobjects.sdk.EventNotifier; 
import com.remobjects.sdk.EventReceiver; 

public class AndroidService 
{ 
    final AndroidService_AsyncProxy androidService; 
    final EventReceiver receiver; 
    EventNotifier notifier; 
    private Handler aHandler; 
    Context context; 
    URI serverURI; 
    Boolean result; 

    public AndroidService() 
    { 
     androidService = SetupAndroidService(); 
     aHandler = new Handler(); 
     receiver = SetupEventReceiver(); 


     /*androidService.beginSubscribeToEvents(true, new AsyncRequest.IAsyncRequestCallback() 
     { 
      @Override 
      public void completed(AsyncRequest aRequest) 
      { 
       androidService.endSubscribeToEvents(aRequest); 
       Log.d("AndroidService", "Subscribed to Events"); 
      } 
      @Override 
      public void failed(AsyncRequest aRequest, Exception aException) 
      { 
       Log.e("AndroidService", "SubscribeToEvents Failed: " + aException.getMessage());  
      } 
     });*/ 
    } 

    public AndroidService_AsyncProxy SetupAndroidService() 
    { 
     try 
     { 
      context = FieldAgent.getAppContext(); 
      serverURI = new URI(context.getString(R.string.server_adress)); 
     } 
     catch (Exception e) 
     { 
      Log.e("AndroidService", e.getMessage()); 
     } 
     final AndroidService_AsyncProxy androidService = new AndroidService_AsyncProxy(serverURI); 

     // Set channel callback 
     androidService.getProxyClientChannel().setChannelCallback(new IClientChannelCallback() { 
      @Override 
      public void requestFailWithException(Exception aException) { 
      Log.e("AndroidService", "Exception : " + aException.getMessage()); 
      } 
      @Override 
      public boolean clientChannelNeedsLogin(Exception aException) { 
       Log.e("AndroidService", "clientChannelNeedsLogin: " + aException.getMessage()); 

       return false; 
      } 
     }); 
     Log.d("AndroidService", "AndroidService Initiated"); 
     return androidService; 
    } 

    public EventReceiver SetupEventReceiver() 
    { 
     EventReceiver receiver = new EventReceiver(androidService, "AndroidServiceReceiver"); 
     receiver.setChannel(ClientChannel.channelWithURI(serverURI)); 
     receiver.setServiceName(androidService._getInterfaceName()); 
     receiver.setMinPollInterval(1); 
     receiver.setMaxPollInterval(3); 

     receiver.addListener(new ROEventsAdapter() { 
      @Override 
      public void OnIdleReportDelivered(final OnIdleReportDeliveredEvent aEvent) 
      { 
       Log.d("AndroidServiceEventReceiver", "OnIdleReportDelivered"); 

       aHandler.post(new Runnable() 
       { 
        @Override 
        public void run() 
        { 
         ReportStruct report = aEvent.get_DeliveredReport(); 

         FieldAgent.setLastReportTime("Last Report Sent " + report.getTime()); 

         Log.d("AndroidServiceEventReceiver", "Stopping MonitorService"); 
         Intent serviceIntent = new Intent(FieldAgent.getAppContext(), 
          MonitorService.class); 
         FieldAgent.getAppContext().stopService(serviceIntent); 

         FieldAgent.setErrorState(FieldAgent.ERRORSTATE_NO_ERROR); 
        } 
       }); 
      } 
     }); 
     Log.d("AndroidService", "EventReceiver Initiated"); 
     return receiver; 
    } 

    private void setResult(Boolean inResult) 
    { 
     result = inResult; 
    } 

    private Boolean getResult() 
    { 
     return result; 
    } 

    public Boolean SendIdleReport(double latitude, double longitude) 
    { 
     Date now = new Date(); 

     androidService.beginAddIdleReport(now, longitude, latitude, "Android Location", true, new AsyncRequest.IAsyncRequestCallback() 
     { 
      @Override 
      public void completed(AsyncRequest aRequest) 
      { 
       androidService.endAddIdleReport(aRequest); 
       Log.d("AndroidService", "IdleReport sent"); 
       setResult(true); 
      } 
      @Override 
      public void failed(AsyncRequest aRequest, Exception aException) 
      { 
       Log.e("AndroidService", "AddIdleReport Failed: " + aException.getMessage());  
       setResult(false); 
      } 
     }); 
     return getResult(); 
    } 
} 

가와가의 :

IAndroidEvents ev = (IAndroidEvents)GetEventSink(typeof(IAndroidEvents), new Guid[] { SessionID }); 

나는이 같은 구독-방법을 사용하여 시도했다 :

public virtual bool SubscribeToEvents() 
{ 
    try 
    { 
     Guid currentSession = SessionID; 

     EventSinkManager.SubscribeClient(currentSession, typeof(IAndroidEvents)); 

     return true; 
    } 
    catch (Exception e) 
    { 
     return false; 
    } 
} 
,

하지만 행운은 없습니다. 채널 콜백 (ClientChannelNeedsLogin) 작동, SendIdleReport() 작동하지만 아무 이벤트 ... 아무도 도울 수 있습니까?

내가 그것을 알아 냈

답변

1

,이 매우 중요 작은 라인 잊고 있었던 :

receiver.start()

관련 문제