gpt4 book ai didi

c# - 如何在 Android 上接收 RemObjects 事件?

转载 作者:行者123 更新时间:2023-12-01 14:20:31 25 4
gpt4 key购买 nike

让我的 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;
}
}

但运气不佳。 channel 回调 (ClientChannelNeedsLogin) 有效,SendIdleReport() 有效,但没有事件...任何人都可以帮忙吗?

最佳答案

我发现了,我忘记了这一非常重要的小行:

接收器.start()

关于c# - 如何在 Android 上接收 RemObjects 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17615175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com