Forum Xamarin.Forms

How can i Advertise multiple ble data with time interval and stop and start advertising as i want?

I am creating a BLE advertising tag in android, which I want to transmit every 10 sec likewise, I want to create multiple BLE tags.
and also I want to give the option to start and stop advertising as the user wants. I am Sharing my main advertising code. suggest any solution for it

using Android.Bluetooth.LE;
using Android.Bluetooth;
public string StartTransmittingData(string tagdata)
{
BluetoothLeAdvertiser leAdvertiser = BluetoothAdapter.DefaultAdapter.BluetoothLeAdvertiser;

        AdvertiseSettings settings = (new AdvertiseSettings.Builder())
                                                .SetConnectable(true)
                                                .SetAdvertiseMode(AdvertiseMode.LowLatency)
                                                .SetTxPowerLevel(AdvertiseTx.PowerMedium)
                                                .Build();

            var mfrid = Convert.ToInt32(("fffe"), 16);
            byte[] raw = tagdata;
            AdvertiseData advertiseData = (new AdvertiseData.Builder())
                                         .SetIncludeDeviceName(true)
                                         .AddManufacturerData(mfrid, raw)
                                         .Build();

            BleAdvertiseCallback callback = new BleAdvertiseCallback();


            leAdvertiser.StartAdvertising(settings, advertiseData, callback);

            return callback.ToString();

    }
Sign In or Register to comment.