1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] How do I scan for Bluetooth Advertising data?

Discussão em 'Mobile' iniciado por Stack, Outubro 25, 2024 às 10:02.

  1. Stack

    Stack Membro Participativo

    I'm fresh into Flutter and have a use case where I want to advertise some data from my device .. I found this package to help me with the same, Upon referring the docs and some more I managed this -

    void advertise() async {
    try {
    String advertisingName = 'Advertising Name';
    print('Advertise function called'); // Debug print statement
    print('Advertising data: $advertisingName'); // Print the data being advertised
    bool a = await Nearby().startAdvertising(
    advertisingName,
    Strategy.P2P_POINT_TO_POINT, // https://developers.google.com/nearby/connections/strategies
    onConnectionInitiated: (String id, ConnectionInfo info) {
    print('Connection initiated with id: $id'); // Debug print statement
    },
    onConnectionResult: (String id, Status status) {
    print('Connection result for id: $id, status: $status'); // Debug print statement
    },
    onDisconnected: (String id) {
    print('Disconnected from id: $id'); // Debug print statement
    },
    serviceId: "com.yourdomain.appname",

    );
    print('Advertising started: $a');
    } catch (exception) {
    print('Exception occurred: $exception'); // Debug print statement
    }
    }


    When I call the function I get the 'Advertising data: Advertising Name' & 'Advertise function called',but when I check for my device on another device in an app like nRF, I don't find my device or anything? What am I missing here? Any alternative approaches are also welcomed.

    Thanks.

    Continue reading...

Compartilhe esta Página