如何从java创建JavaScript数组。util。使用NativeScript将java服务设置为Android
我正在制作一个访问蓝牙经典设备的算法,在这个算法中,我从一个直接从Android服务获得的实例中获得一个java类型的集合。util。设置时,我需要在此集合中进行交互,以获取存在的对象的属性,并根据使用JavaScript语言在NativeScript中构建的实体模型构建一个新数组
在使用JavaScript语言的NativeScript中,应该以何种方式实现这种兴趣
下面是建议的代码,您可以了解我想做什么:
Bluetooth.getBoundedDevices = function(){
java.util.Set<安卓.bluetooth.BluetoothDevice> pairedDevices = adapter.getBondedDevices();
var obArrayDevices = new ObservableArray();
// If there are paired devices
if (pairedDevices.size() > 0) {
// Loop through paired devices
for (deviceAndroid of pairedDevices.toArray([{}])) {
var device = new Observable({
type: 'scanResult',
UUID: deviceAndroid.getAddress(),
name: deviceAndroid.getName(),
RSSI: 0,
state: 'disconnected'
});
console.log("dispositivo Encontrado:");
console.dir(device);
obArrayDevices.add(device);
}
}
return obArrayDevices;
}
# 1 楼答案
Set.toArray()返回一个java。Java中的lang.Object[],在JavaScript中使用时将封送到JavaScript数组