You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Doubt : how to listen to List of bluetooth devices instead of single Map object Stream<dynamic> onDiscovery() { return _discoveryChannel.receiveBroadcastStream().map((map) => BluetoothDevice.fromMap(map)); }
wrote new event channel in FlutterBluetoothSerialPlugin class
`
private final StreamHandler discoveryStreamHandler = new StreamHandler() {
List<Map<String, Object>> list = new ArrayList<>();
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("discoveryStreamHandler ","onReceive");
final String action = intent.getAction();
Log.d(TAG, action);
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
Map<String, Object> ret = new HashMap<>();
ret.put("address", device.getAddress());
ret.put("name", device.getName());
ret.put("type", device.getType());
list.add(ret);
// Log.d("list",list.toString());
discoverySink.success(ret);
}else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
/* want to return list here while listening to it getting error as "List not a subtype of map<dynamic,dynamic>
*/
// discoverySink.success(list);
}
}
};
@Override
public void onListen(Object o, EventSink eventSink) {
discoverySink = eventSink;
if (ContextCompat.checkSelfPermission(registrar.activity(),
Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(registrar.activity(),
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
REQUEST_COARSE_LOCATION_PERMISSIONS);
//Doubt : what shall i return here?
}
Log.e("discoveryStreamHandler ","onListen"+ registrar.activeContext());
registrar.activeContext().registerReceiver(mReceiver,
new IntentFilter(BluetoothDevice.ACTION_FOUND));
registrar.activeContext().registerReceiver(mReceiver,
new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
mBluetoothAdapter.startDiscovery();
}
@Override
public void onCancel(Object o) {
Log.d("discoveryStreamHandler", "onCancel");
discoverySink = null;
registrar.activity().unregisterReceiver(mReceiver);
}
};`
Called from main.dart as
bluettoth.getdevices().listen.
I'm getting list of devices but have some doubt which i listed in code snippet. Please revert
The text was updated successfully, but these errors were encountered:
I'm new in flutter and wanted to add some new feature in this plugin ,
static const EventChannel _discoveryChannel = const EventChannel('$namespace/discovery');
//Doubt : how to listen to List of bluetooth devices instead of single Map object
Stream<dynamic> onDiscovery() { return _discoveryChannel.receiveBroadcastStream().map((map) => BluetoothDevice.fromMap(map)); }
`
private final StreamHandler discoveryStreamHandler = new StreamHandler() {
/* want to return list here while listening to it getting error as "List not a subtype of map<dynamic,dynamic>
*/
// discoverySink.success(list);
}
}
};
//Doubt : what shall i return here?
Called from main.dart as
bluettoth.getdevices().listen.
I'm getting list of devices but have some doubt which i listed in code snippet. Please revert
The text was updated successfully, but these errors were encountered: