use of android.bluetooth.BluetoothManager in project Gadgetbridge by Freeyourgadget.
the class DiscoveryActivity method checkBluetoothAvailable.
private boolean checkBluetoothAvailable() {
BluetoothManager bluetoothService = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
if (bluetoothService == null) {
LOG.warn("No bluetooth available");
this.adapter = null;
return false;
}
BluetoothAdapter adapter = bluetoothService.getAdapter();
if (adapter == null) {
LOG.warn("No bluetooth available");
this.adapter = null;
return false;
}
if (!adapter.isEnabled()) {
LOG.warn("Bluetooth not enabled");
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBtIntent);
this.adapter = null;
return false;
}
this.adapter = adapter;
return true;
}
use of android.bluetooth.BluetoothManager in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTServer method initialize.
boolean initialize() {
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothGattServer = bluetoothManager.openGattServer(mContext, this);
if (mBluetoothGattServer == null) {
return false;
}
BluetoothGattService pebbleGATTService = new BluetoothGattService(SERVER_SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY);
pebbleGATTService.addCharacteristic(new BluetoothGattCharacteristic(READ_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ));
writeCharacteristics = new BluetoothGattCharacteristic(WRITE_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_WRITE);
writeCharacteristics.addDescriptor(new BluetoothGattDescriptor(CHARACTERISTICS_CONFIGURATION_DESCRIPTOR, BluetoothGattDescriptor.PERMISSION_WRITE));
pebbleGATTService.addCharacteristic(writeCharacteristics);
mBluetoothGattServer.addService(pebbleGATTService);
return true;
}
use of android.bluetooth.BluetoothManager in project android_wear_for_ios by shiitakeo.
the class BLEService method onStart.
@TargetApi(20)
@Override
public void onStart(Intent intent, int startID) {
Log.d(TAG_LOG, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
IntentFilter intent_filter = new IntentFilter();
intent_filter.addAction(action_positive);
intent_filter.addAction(action_negative);
intent_filter.addAction(action_delete);
intent_filter.addAction(action_renotify);
registerReceiver(message_receiver, intent_filter);
vib = (Vibrator) getSystemService(VIBRATOR_SERVICE);
notificationManager = NotificationManagerCompat.from(getApplicationContext());
packet_processor = new PacketProcessor();
icon_image_manager = new IconImageManager();
if (bluetooth_gatt != null) {
bluetooth_gatt.disconnect();
bluetooth_gatt.close();
bluetooth_gatt = null;
}
if (bluetooth_adapter != null) {
bluetooth_adapter = null;
}
if (api_level >= 21) {
if (le_scanner != null) {
Log.d(TAG_LOG, "status: ble reset");
stop_le_scanner();
}
}
is_connect = false;
is_subscribed_characteristics = false;
iphone_uuid = "";
start_time = 0;
is_time = false;
// 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);
bluetooth_adapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (bluetooth_adapter == null) {
Log.d(TAG_LOG, "ble adapter is null");
return;
}
if (api_level >= 21) {
Log.d(TAG_LOG, "start BLE scan @ lescan");
start_le_scanner();
} else {
Log.d(TAG_LOG, "start BLE scan @ BluetoothAdapter");
bluetooth_adapter.startLeScan(le_scan_callback);
}
//music control notification
Intent __intent = new Intent(this, MusicControlActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, __intent, 0);
Intent _intent_delete = new Intent();
_intent_delete.setAction(action_renotify);
PendingIntent _delete_action = PendingIntent.getBroadcast(getApplicationContext(), notification_id, _intent_delete, PendingIntent.FLAG_ONE_SHOT);
Notification.Builder notificationBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.whatsapp).setContentTitle("music💿").setContentIntent(pendingIntent).addAction(R.drawable.resume, "Controller Open", pendingIntent).setLocalOnly(true).setDeleteIntent(_delete_action).extend(new Notification.WearableExtender().setContentAction(0).setHintHideIcon(true));
Notification _notification = notificationBuilder.build();
// _notification.flags = _notification.flags | Notification.FLAG_ONGOING_EVENT;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(id_music_control, _notification);
notification_id++;
}
use of android.bluetooth.BluetoothManager in project android_wear_for_ios by shiitakeo.
the class MusicControlActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_control);
Log.d(TAG_LOG, "-=-=-=-=-=-=-=-= onCreate @ MusicControlActivity -=-=-=-=-=-=-=-=-=");
IntentFilter intent_filter = new IntentFilter();
intent_filter.addAction(set_artist_info);
intent_filter.addAction(set_title_info);
registerReceiver(message_receiver, intent_filter);
if (bluetooth_gatt != null) {
bluetooth_gatt.disconnect();
bluetooth_gatt.close();
bluetooth_gatt = null;
}
if (bluetooth_adapter != null) {
bluetooth_adapter = null;
}
if (api_level >= 21) {
if (le_scanner != null) {
Log.d(TAG_LOG, "status: ble reset");
stop_le_scanner();
}
}
is_connect = false;
iphone_uuid = "";
// 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);
bluetooth_adapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (bluetooth_adapter == null) {
Log.d(TAG_LOG, "ble adapter is null");
return;
}
if (api_level >= 21) {
Log.d(TAG_LOG, "start BLE scan @ lescan");
start_le_scanner();
} else {
Log.d(TAG_LOG, "start BLE scan @ BluetoothAdapter");
bluetooth_adapter.startLeScan(le_scan_callback);
}
}
use of android.bluetooth.BluetoothManager in project android-beacon-library by AltBeacon.
the class CycledLeScanner method getBluetoothAdapter.
protected BluetoothAdapter getBluetoothAdapter() {
try {
if (mBluetoothAdapter == null) {
// Initializes Bluetooth adapter.
final BluetoothManager bluetoothManager = (BluetoothManager) mContext.getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null) {
LogManager.w(TAG, "Failed to construct a BluetoothAdapter");
}
}
} catch (SecurityException e) {
// Thrown by Samsung Knox devices if bluetooth access denied for an app
LogManager.e(TAG, "Cannot consruct bluetooth adapter. Security Exception");
}
return mBluetoothAdapter;
}
Aggregations