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