Example usage for android.bluetooth BluetoothAdapter ACTION_SCAN_MODE_CHANGED

List of usage examples for android.bluetooth BluetoothAdapter ACTION_SCAN_MODE_CHANGED

Introduction

In this page you can find the example usage for android.bluetooth BluetoothAdapter ACTION_SCAN_MODE_CHANGED.

Prototype

String ACTION_SCAN_MODE_CHANGED

To view the source code for android.bluetooth BluetoothAdapter ACTION_SCAN_MODE_CHANGED.

Click Source Link

Document

Broadcast Action: Indicates the Bluetooth scan mode of the local Adapter has changed.

Usage

From source file:com.molidt.easyandroid.bluetooth.BluetoothFragmentV4.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!isInit) {
        initPlugin(_activity);//from  w w  w. j av  a2s.co m
    }

    _Handler = new Handler();

    //if UUID is null,using the package name to setting the default UUID
    if (BLUETOOTH_UUID == null) {
        BLUETOOTH_UUID = UUID.fromString(_activity.getPackageName());
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
    _activity.registerReceiver(mFoundReceiver, filter);

    if (isSupportBLE) {
        Intent gattServiceIntent = new Intent(_activity, BluetoothLeService.class);
        _activity.bindService(gattServiceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
    }
}

From source file:com.thelastcrusade.soundstream.components.ConnectFragment.java

private void registerReceivers() {
    this.broadcastRegistrar = new BroadcastRegistrar();
    this.broadcastRegistrar
            .addLocalAction(ConnectionService.ACTION_HOST_CONNECTED, new IBroadcastActionHandler() {

                @Override//from  www  . ja v a  2s.c  o  m
                public void onReceiveAction(Context context, Intent intent) {
                    joinView.setEnabled(true);
                    joinView.findViewById(R.id.searching).setVisibility(View.INVISIBLE);
                    //switch 
                    Transitions.transitionToHome((CoreActivity) getActivity());
                    ((CoreActivity) getActivity()).enableSlidingMenu();

                    //add the playbar fragment onto the active content view
                    ((CoreActivity) getActivity()).showPlaybar();
                }
            }).addGlobalAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED, new IBroadcastActionHandler() {

                @Override
                public void onReceiveAction(Context context, Intent intent) {
                    int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE,
                            BluetoothAdapter.SCAN_MODE_NONE);
                    if (joinView != null) {
                        switch (mode) {
                        case BluetoothAdapter.SCAN_MODE_NONE: //fall through to connectable
                        case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
                            isSearching = false;
                            setJoinToDefaultState();
                            break;
                        case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
                            isSearching = true;
                            setJoinToSearchingState();
                            break;
                        default:
                            Log.wtf(TAG, "Recieved scan mode changed with unknown mode");
                            break;
                        }
                    }
                }
            }).register(this.getActivity());
}

From source file:com.thelastcrusade.soundstream.components.NetworkFragment.java

private void registerReceivers() {
    this.broadcastRegistrar = new BroadcastRegistrar();
    this.broadcastRegistrar
            .addLocalAction(ConnectionService.ACTION_FIND_FINISHED, new IBroadcastActionHandler() {

                @Override//from   www .jav a 2 s .  com
                public void onReceiveAction(Context context, Intent intent) {
                    onFindFinished(intent);
                }
            }).addLocalAction(UserList.ACTION_USER_LIST_UPDATE, new IBroadcastActionHandler() {

                @Override
                public void onReceiveAction(Context context, Intent intent) {
                    updateUserView();
                }
            }).addLocalAction(ConnectionService.ACTION_GUEST_CONNECTED, new IBroadcastActionHandler() {
                @Override
                public void onReceiveAction(Context context, Intent intent) {
                    setDisconnectDisbandBtn();
                }
            }).addLocalAction(ConnectionService.ACTION_HOST_CONNECTED, new IBroadcastActionHandler() {
                @Override
                public void onReceiveAction(Context context, Intent intent) {
                    setDisconnectDisbandBtn();
                }
            }).addGlobalAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED, new IBroadcastActionHandler() {

                @Override
                public void onReceiveAction(Context context, Intent intent) {
                    int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE,
                            BluetoothAdapter.SCAN_MODE_NONE);

                    if (joinDifferentNetworkButton != null) {
                        switch (mode) {
                        case BluetoothAdapter.SCAN_MODE_NONE:
                        case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
                            setButtonToDefaultState(joinDifferentNetworkButton);
                            isSearchingJoinDifferent = false;
                            break;
                        case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
                            setButtonToSearchingState(joinDifferentNetworkButton);
                            isSearchingJoinDifferent = true;
                            break;
                        default:
                            Log.wtf(TAG, "Recieved scan mode changed with unknown mode");
                            break;
                        }
                    }

                }
            }).register(this.getActivity());
}