如何在 Gluon Charm down 3.0.0 中创建自定义插件?或类似的东西。
我有包 sk.ltorok.gluon.bluetooth.plugins,这个包包含两个类 BluetoothServiceFactory 和 BluetoothService,这是代码:
package sk.ltorok.gluon.bluetooth.plugins;
import com.gluonhq.charm.down.DefaultServiceFactory;
public class BluetoothServiceFactory extends DefaultServiceFactory<BluetoothService> {
public BluetoothServiceFactory() {
super(BluetoothService.class);
}
}
……下一节课
package sk.ltorok.gluon.bluetooth.plugins;
import java.util.List;
public interface BluetoothService {
List<String> getPairedDevices();
}
在构造函数的基本视图中(我使用 Gluon Mobile)是这样的:
public class BasicView extends View {
private BluetoothService bluetoothService;
public BasicView(String name) {
super(name);
Services.registerServiceFactory(new BluetoothServiceFactory());
System.out.println("REGISTER BLUETOOTH");
boolean isPresent = Services.get(BluetoothService.class).isPresent();
System.out.println("BLUETOOTH PRESENT: " + isPresent);
if (isPresent) {
Optional<BluetoothService> opt = Services.get(BluetoothService.class);
bluetoothService = opt.get();
}
...等下一个代码...
在 Andoid/Java Packages 文件夹中,我有包 sk.ltorok.gluon.bluetooth.plugins.android 并且有实现 AndroidBluetoothService 类
package sk.ltorok.gluon.bluetooth.plugins.android;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Build;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javafxports.android.FXActivity;
import sk.ltorok.gluon.bluetooth.plugins.BluetoothService;
public class AndroidBluetoothService implements BluetoothService {
// ...
}
但是 isPresent 总是错误的!