How to use Broadcast Receiver in Xamarin

Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

I need to get notification of connection status from Bluetooth device. So I planned to use a broadcast receiver. How to convert below code to xamarin?

Code :`private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();

    if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                                             BluetoothAdapter.ERROR);
        switch (state) {
        case BluetoothAdapter.STATE_OFF:
            setButtonText("Bluetooth off");
            break;
        case BluetoothAdapter.STATE_TURNING_OFF:
            setButtonText("Turning Bluetooth off...");
            break;
        case BluetoothAdapter.STATE_ON:
            setButtonText("Bluetooth on");
            break;
        case BluetoothAdapter.STATE_TURNING_ON:
            setButtonText("Turning Bluetooth on...");
            break;
        }
    }
}

};`

Please guide Thanks

Tagged:

Best Answer

Answers

  • Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

    @mirkaram do we need any code to the main activity class

Sign In or Register to comment.