use of android.bluetooth.BluetoothAdapter in project android-beacon-library by AltBeacon.
the class CycledLeScannerForLollipop method getScanner.
private BluetoothLeScanner getScanner() {
try {
if (mScanner == null) {
LogManager.d(TAG, "Making new Android L scanner");
BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
if (bluetoothAdapter != null) {
mScanner = getBluetoothAdapter().getBluetoothLeScanner();
}
if (mScanner == null) {
LogManager.w(TAG, "Failed to make new Android L scanner");
}
}
} catch (SecurityException e) {
LogManager.w(TAG, "SecurityException making new Android L scanner");
}
return mScanner;
}
use of android.bluetooth.BluetoothAdapter in project android-beacon-library by AltBeacon.
the class CycledLeScannerForJellyBeanMr2 method postStopLeScan.
private void postStopLeScan() {
final BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
if (bluetoothAdapter == null) {
return;
}
final BluetoothAdapter.LeScanCallback leScanCallback = getLeScanCallback();
mScanHandler.removeCallbacksAndMessages(null);
mScanHandler.post(new Runnable() {
@Override
public void run() {
try {
//noinspection deprecation
bluetoothAdapter.stopLeScan(leScanCallback);
} catch (Exception e) {
LogManager.e(e, TAG, "Internal Android exception in stopLeScan()");
}
}
});
}
use of android.bluetooth.BluetoothAdapter in project android-beacon-library by AltBeacon.
the class CycledLeScannerForJellyBeanMr2 method postStartLeScan.
private void postStartLeScan() {
final BluetoothAdapter bluetoothAdapter = getBluetoothAdapter();
if (bluetoothAdapter == null) {
return;
}
final BluetoothAdapter.LeScanCallback leScanCallback = getLeScanCallback();
mScanHandler.removeCallbacksAndMessages(null);
mScanHandler.post(new Runnable() {
@Override
public void run() {
try {
//noinspection deprecation
bluetoothAdapter.startLeScan(leScanCallback);
} catch (Exception e) {
LogManager.e(e, TAG, "Internal Android exception in startLeScan()");
}
}
});
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by DirtyUnicorns.
the class ExternalSharedPermsTest method testRunLocationAndBluetooth.
/** The use of location manager and bluetooth below are simply to simulate an app that
* tries to use them, so we can verify whether permissions are granted and accessible.
* */
public void testRunLocationAndBluetooth() {
LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
public void onLocationChanged(Location location) {
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
});
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if ((mBluetoothAdapter != null) && (!mBluetoothAdapter.isEnabled())) {
mBluetoothAdapter.getName();
}
}
use of android.bluetooth.BluetoothAdapter in project android_frameworks_base by AOSPA.
the class Tethering method setBluetoothTethering.
private void setBluetoothTethering(final boolean enable, final ResultReceiver receiver) {
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter == null || !adapter.isEnabled()) {
Log.w(TAG, "Tried to enable bluetooth tethering with null or disabled adapter. null: " + (adapter == null));
sendTetherResult(receiver, ConnectivityManager.TETHER_ERROR_SERVICE_UNAVAIL);
return;
}
adapter.getProfileProxy(mContext, new ServiceListener() {
@Override
public void onServiceDisconnected(int profile) {
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
((BluetoothPan) proxy).setBluetoothTethering(enable);
// TODO: Enabling bluetooth tethering can fail asynchronously here.
// We should figure out a way to bubble up that failure instead of sending success.
int result = ((BluetoothPan) proxy).isTetheringOn() == enable ? ConnectivityManager.TETHER_ERROR_NO_ERROR : ConnectivityManager.TETHER_ERROR_MASTER_ERROR;
sendTetherResult(receiver, result);
if (enable && isTetherProvisioningRequired()) {
scheduleProvisioningRechecks(ConnectivityManager.TETHERING_BLUETOOTH);
}
adapter.closeProfileProxy(BluetoothProfile.PAN, proxy);
}
}, BluetoothProfile.PAN);
}
Aggregations