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!");
}
Aggregations