Example usage for android.bluetooth BluetoothManager getAdapter

List of usage examples for android.bluetooth BluetoothManager getAdapter

Introduction

In this page you can find the example usage for android.bluetooth BluetoothManager getAdapter.

Prototype

public BluetoothAdapter getAdapter() 

Source Link

Document

Get the default BLUETOOTH Adapter for this device.

Usage

From source file:com.coinblesk.client.utils.UIUtils.java

private static void disableBluetooth(Activity activity) {
    BluetoothManager bm = (BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter mBluetoothAdapter = bm.getAdapter();
    if (mBluetoothAdapter != null && mBluetoothAdapter.isEnabled()) {
        mBluetoothAdapter.disable();/*from  www. j a v a  2 s.  c  o m*/
        Intent exchangeRateChanged = new Intent(Constants.EXCHANGE_RATE_CHANGED_ACTION);
        LocalBroadcastManager.getInstance(activity).sendBroadcast(exchangeRateChanged);
    }
}

From source file:cloudbank.ble.activity.DeviceScanActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scan);

    //getSupportActionBar().setElevation(3);
    //getSupportActionBar().setTitle(R.string.app_name);

    // Sets the Toolbar to act as the ActionBar for this Activity window.
    // Make sure the toolbar exists in the activity and is not null

    // Use this check to determine whether BLE is supported on the device.  Then you can
    // selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
        finish();//  ww w . j a va 2s  . c  o m
    }

    // Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
    // BluetoothAdapter through BluetoothManager.
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();

    // Checks if Bluetooth is supported on the device.
    if (mBluetoothAdapter == null) {
        Toast.makeText(this, R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.fragHolder, new ScanListFragment());
    ft.commit();
}

From source file:org.jraf.android.bikey.app.heartrate.bluetooth.BleScanListFragment.java

private boolean ensureBluetoothEnabled() {
    BluetoothManager bluetoothManager = (BluetoothManager) getActivity()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = bluetoothManager.getAdapter();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(intent, REQUEST_ENABLE_BT);
        return false;
    }/*from  w ww.  ja  va 2s . co m*/
    return true;
}

From source file:com.djit.mixfader.sample.BaseActivity.java

/**
 * Handles permissions and features needed by the app
 *//* w ww.j  a v a  2  s .co  m*/
@Override
protected void onResume() {
    super.onResume();

    // Asks for Bluetooth activation is needed
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    final BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        final Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    // Asks for permissions if needed
    final int checkCoarseLocation = ContextCompat.checkSelfPermission(this,
            "android.permission.ACCESS_COARSE_LOCATION");
    final int checkFineLocation = ContextCompat.checkSelfPermission(this,
            "android.permission.ACCESS_FINE_LOCATION");
    if (checkCoarseLocation == PackageManager.PERMISSION_DENIED
            && checkFineLocation == PackageManager.PERMISSION_DENIED) {
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
                MY_PERMISSIONS_REQUEST_COARSE_LOCATION);
    } else {
        // Ask for location service if needed
        if (needToEnableLocation(this)) {
            final Intent viewIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(viewIntent);
        }
    }
}

From source file:com.google.android.apps.forscience.ble.DeviceDiscoverer.java

protected DeviceDiscoverer(Context context) {
    mContext = context.getApplicationContext();
    BluetoothManager manager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothAdapter = manager.getAdapter();
    mDevices = new ArrayMap<>();
}

From source file:com.orange.beaconme_sdk.ble.control.BLEDeviceScanner.java

@Override
public void onCreate() {
    Log.d(TAG, "onCreate");
    super.onCreate();
    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    mAdapter = bluetoothManager.getAdapter();

    if (mAdapter != null && mAdapter.isEnabled()) {
        startScanning();// ww  w  . ja v a2 s. c o  m
        LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(receiver, intentFilter);
    } else {
        stopSelf();
    }
}

From source file:org.physical_web.physicalweb.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    // Lock to prevent onResume from running until all permissions are granted
    if (!PermissionCheck.getInstance().isCheckingPermissions()) {
        Log.d(TAG, "resumed MainActivity");
        BluetoothManager btManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
        BluetoothAdapter btAdapter = btManager != null ? btManager.getAdapter() : null;
        if (btAdapter == null) {
            Toast.makeText(getApplicationContext(), R.string.error_bluetooth_support, Toast.LENGTH_LONG).show();
            finish();//from  w w  w  . j  av a2s.  com
            return;
        }
        if (Utils.checkIfUserHasOptedIn(this)) {
            Log.d(TAG, "checkingPermissions");
            checkPermissions(btAdapter);
        } else {
            // Show the oob activity
            Intent intent = new Intent(this, OobActivity.class);
            startActivity(intent);
        }
    }
}

From source file:za.co.paulscott.antifitness.ModuleActivity.java

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

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (!bluetoothManager.getAdapter().isEnabled()) {
        final Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    }//ww w  . jav a  2s. c o  m

    getApplicationContext().bindService(new Intent(this, MetaWearBLEService.class), this,
            Context.BIND_AUTO_CREATE);

    if (savedInstanceState != null) {
        device = (BluetoothDevice) savedInstanceState.getParcelable(EXTRA_BLE_DEVICE);
        moduleFragment = (ModuleFragment) getSupportFragmentManager().getFragment(savedInstanceState,
                "mContent");
    }
}

From source file:com.github.google.beaconfig.ScanningActivity.java

private void setupScanner() {
    Log.d(TAG, "Setting up scanner...");
    BluetoothManager manager = (BluetoothManager) getApplicationContext()
            .getSystemService(Context.BLUETOOTH_SERVICE);
    btAdapter = manager.getAdapter();

    requestBluetoothOn();//from  w  w  w .  j  av  a 2 s. c  o  m
}

From source file:com.mikel.poseidon.Activities.preferences.BluetoothDeviceActivity.java

@Override
protected void onResume() {
    super.onResume();

    final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        mBluetoothAdapter = bluetoothManager.getAdapter();
    }/* ww w.j a va 2s  . c  om*/

    if (!mBluetoothAdapter.isEnabled()) {
        if (!mBluetoothAdapter.isEnabled()) {
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, 1);
        }
    }

    mPairedDevice = mSettings.getString("macaddress", "");

    if (!mPairedDevice.isEmpty()) {
        BluetoothDevice bluetoothDevice = new BluetoothDevice();
        bluetoothDevice.macaddress = mPairedDevice;
        bluetoothDevice.name = "Currently not found";
        bluetoothDevice.checked = true;
        bluetoothDevice.rssi = -1000;
        mFragment.foundDevice(bluetoothDevice);
    }
}