Search in sources :

Example 11 with BluetoothManager

use of android.bluetooth.BluetoothManager in project aware-client by denzilferreira.

the class Bluetooth method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    AUTHORITY = Bluetooth_Provider.getAuthority(this);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    IntentFilter filter = new IntentFilter();
    filter.addAction(Bluetooth.ACTION_AWARE_BLUETOOTH_REQUEST_SCAN);
    filter.addAction(BluetoothDevice.ACTION_FOUND);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    registerReceiver(bluetoothMonitor, filter);
    Intent backgroundService = new Intent(ACTION_AWARE_BLUETOOTH_REQUEST_SCAN);
    bluetoothScan = PendingIntent.getBroadcast(this, 0, backgroundService, PendingIntent.FLAG_UPDATE_CURRENT);
    REQUIRED_PERMISSIONS.add(Manifest.permission.BLUETOOTH);
    REQUIRED_PERMISSIONS.add(Manifest.permission.BLUETOOTH_ADMIN);
    // we need this permission for BT scanning to work
    REQUIRED_PERMISSIONS.add(Manifest.permission.ACCESS_COARSE_LOCATION);
    bluetoothAdapter = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) ? ((BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter() : BluetoothAdapter.getDefaultAdapter();
    if (bluetoothAdapter == null) {
        stopSelf();
        return;
    }
    // Check if the device can do BLE scans.
    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
        BLE_SUPPORT = true;
    enableBT = new Intent(this, Bluetooth.class);
    enableBT.putExtra("action", ACTION_AWARE_ENABLE_BT);
    if (Aware.DEBUG)
        Log.d(TAG, "Bluetooth service created!");
}
Also used : IntentFilter(android.content.IntentFilter) BluetoothManager(android.bluetooth.BluetoothManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Aggregations

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