问题
How to create custom plugin in Gluon Charm down 3.0.0? Or something similar.
I have package sk.ltorok.gluon.bluetooth.plugins and this package contains two classes BluetoothServiceFactory and BluetoothService and this is code:
package sk.ltorok.gluon.bluetooth.plugins;
import com.gluonhq.charm.down.DefaultServiceFactory;
public class BluetoothServiceFactory extends DefaultServiceFactory<BluetoothService> {
public BluetoothServiceFactory() {
super(BluetoothService.class);
}
}
... and next class
package sk.ltorok.gluon.bluetooth.plugins;
import java.util.List;
public interface BluetoothService {
List<String> getPairedDevices();
}
In Basic view in constructor (I using Gluon Mobile) is this:
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();
}
... etc. next code ...
In Andoid/Java Packages folder I have package sk.ltorok.gluon.bluetooth.plugins.android and there is implementation AndroidBluetoothService class
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 {
// ...
}
BUT isPresent is always false!
来源:https://stackoverflow.com/questions/40261409/gluon-charm-down-3-0-0-how-to-create-cusom-plugin