无法让我的 Android 应用接收 RemObjects 事件...
这是Android(java)类:
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() 有效,但没有事件......有人可以帮忙吗?