私は何の運もなく、このことを数日間やっています。これがjava2pas
提供するものですBeaconManager$ServiceReadyCallback
:
[JavaSignature('com/estimote/sdk/BeaconManager$ServiceReadyCallback')]
JBeaconManager_ServiceReadyCallback = interface(JObject)
['{335D3A89-7137-44CE-9969-BECC2F3AB8AC}']
procedure onServiceReady ; cdecl; // ()V A: $401
end;
そこから、次のように匿名メソッドを作成しました。
TAnServiceReadyCallBack = reference to function : JBeaconManager_ServiceReadyCallback;
私がこれをどのように呼ぶか以下:
var
an : TAnServiceReadyCallBack;
bm : JBeaconManager;
begin
bm := TJBeaconManager.JavaClass.init(SharedActivityContext);
an := function : JBeaconManager_ServiceReadyCallback
begin
Result := TJBeaconManager_ServiceReadyCallback.Wrap((context as ILocalObject).GetObjectID);
if Assigned(Result) then
Memo1.Lines.Add('servicereadycallback init')
else
Memo1.Lines.Add('servicereadycallback not init')
end;
bm.connect(an);
その bm.connect(an) 呼び出しで、次のように受け取りました。
java.lang.ClassCastException: com.embarcadero.firemonkey.FMXNativeActivity cannot be cast to com.estimote.sdk.BeaconManager$ServiceReadyCallback
これはestimote sdkによるものです:
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override public void onServiceReady() {
try {
beaconManager.startRanging(ALL_ESTIMOTE_BEACONS);
} catch (RemoteException e) {
Log.e(TAG, "Cannot start ranging", e);
}
}
});
beacon sdk
connect メソッドのコードは次のとおりです。
public void connect(ServiceReadyCallback callback)
{
if (!checkPermissionsAndService()) {
L.e("AndroidManifest.xml does not contain android.permission.BLUETOOTH or android.permission.BLUETOOTH_ADMIN permissions. BeaconService may be also not declared in AndroidManifest.xml.");
}
this.callback = ((ServiceReadyCallback)Preconditions.checkNotNull(callback, "callback cannot be null"));
if (isConnectedToService()) {
callback.onServiceReady();
}
boolean bound = this.context.bindService(new Intent(this.context, BeaconService.class), this.serviceConnection, 1);
if (!bound) {
L.w("Could not bind service: make sure thatcom.estimote.sdk.service.BeaconService is declared in AndroidManifest.xml");
}
}
delphi
また、次のようなクラスを作成しようとしました。
TServiceReadyCallback = class(TJavaLocal,
JBeaconManager_ServiceReadyCallback)
private
fParent: TForm4;
public
constructor Create(parent: TForm4; context: JContext);
function equals(o: JObject): boolean; cdecl;
function getClass: Jlang_Class; cdecl;
function hashCode: Integer; cdecl;
procedure notify; cdecl;
procedure notifyAll; cdecl;
function toString: JString; cdecl;
procedure wait; overload; cdecl;
procedure wait(millis: Int64); overload; cdecl;
procedure wait(millis: Int64; nanos: Integer); overload; cdecl;
procedure onServiceReady; cdecl;
end;
constructor TServiceReadyCallback.Create(parent: TForm4;
context: JContext);
begin
fParent := parent;
fParent.Memo1.Lines.Add('ServiceReadyCallback Created');
end;
このクラスを使用して、次のように使用しました:
var
fservice: TServiceReadyCallback;
context: JContext;
bm : JBeaconManager;
begin
CallInUIThreadAndWaitFinishing(
procedure
begin
context := SharedActivityContext;
bm := TJBeaconManager.JavaClass.init(context);
fservice := TServiceReadyCallback.Create(Self, context);
bm.connect(fservice);
end);
end;
これを使用して私はcallback cannot be null' from beaconmanager.java
ラインを受け取りました
this.callback = ((ServiceReadyCallback)Preconditions.checkNotNull(callback, "callback cannot be null"));
私のクライアントが私に圧力をかけているので、私はこれをひどく必要としています. 私はこれを少なくとも3〜4か月間調査してきましたが、運がありません. これを解決するのを手伝ってくれる人はいますか?