Search in sources :

Example 1 with BluetoothManager

use of android.bluetooth.BluetoothManager in project Android-Developers-Samples by johnjohndoe.

the class DeviceScanActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setTitle(R.string.title_devices);
    mHandler = new Handler();
    // 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();
    }
    // 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;
    }
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) Handler(android.os.Handler)

Example 2 with BluetoothManager

use of android.bluetooth.BluetoothManager in project physical-web by google.

the class BroadcastActivity method checkIfBluetoothIsEnabled.

// Check if bluetooth is on
private boolean checkIfBluetoothIsEnabled() {
    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        Log.d(TAG, "not enabled");
        return false;
    }
    Log.d(TAG, "enabled");
    return true;
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 3 with BluetoothManager

use of android.bluetooth.BluetoothManager in project physical-web by google.

the class MainActivity method onResume.

@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();
            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);
        }
    }
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) Intent(android.content.Intent) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 4 with BluetoothManager

use of android.bluetooth.BluetoothManager in project physical-web by google.

the class BroadcastActivity method hasBleAdvertiseCapability.

// Check if the given bluetooth hardware
// on the current device supports ble advertisemetns
@TargetApi(21)
private boolean hasBleAdvertiseCapability() {
    BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (bluetoothManager.getAdapter().getBluetoothLeAdvertiser() == null) {
        Log.d(TAG, "cant advertise");
        return false;
    }
    Log.d(TAG, "can advertise");
    return true;
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) TargetApi(android.annotation.TargetApi)

Example 5 with BluetoothManager

use of android.bluetooth.BluetoothManager in project physical-web by google.

the class PhysicalWebBroadcastService method onCreate.

/////////////////////////////////
// callbacks
/////////////////////////////////
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "SERVICE onCreate");
    BluetoothManager bluetoothManager = (BluetoothManager) getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothLeAdvertiser = bluetoothManager.getAdapter().getBluetoothLeAdvertiser();
    mNotificationManager = NotificationManagerCompat.from(this);
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager)

Aggregations

BluetoothManager (android.bluetooth.BluetoothManager)10 BluetoothAdapter (android.bluetooth.BluetoothAdapter)3 Intent (android.content.Intent)3 TargetApi (android.annotation.TargetApi)2 IntentFilter (android.content.IntentFilter)2 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)1 BluetoothGattDescriptor (android.bluetooth.BluetoothGattDescriptor)1 BluetoothGattService (android.bluetooth.BluetoothGattService)1 Handler (android.os.Handler)1