Search in sources :

Example 66 with BluetoothAdapter

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;
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 67 with BluetoothAdapter

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()");
            }
        }
    });
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 68 with BluetoothAdapter

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()");
            }
        }
    });
}
Also used : BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 69 with BluetoothAdapter

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();
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) BluetoothAdapter(android.bluetooth.BluetoothAdapter) Location(android.location.Location)

Example 70 with BluetoothAdapter

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);
}
Also used : ServiceListener(android.bluetooth.BluetoothProfile.ServiceListener) BluetoothProfile(android.bluetooth.BluetoothProfile) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Aggregations

BluetoothAdapter (android.bluetooth.BluetoothAdapter)87 Intent (android.content.Intent)15 Location (android.location.Location)12 LocationListener (android.location.LocationListener)12 LocationManager (android.location.LocationManager)12 Bundle (android.os.Bundle)12 BluetoothDevice (android.bluetooth.BluetoothDevice)11 IntentFilter (android.content.IntentFilter)7 Handler (android.os.Handler)6 TextToSpeech (android.speech.tts.TextToSpeech)6 ArrayAdapter (android.widget.ArrayAdapter)6 TextView (android.widget.TextView)6 BluetoothActivityEnergyInfo (android.bluetooth.BluetoothActivityEnergyInfo)5 BluetoothProfile (android.bluetooth.BluetoothProfile)5 ServiceListener (android.bluetooth.BluetoothProfile.ServiceListener)5 ScanFilter (android.bluetooth.le.ScanFilter)5 WifiActivityEnergyInfo (android.net.wifi.WifiActivityEnergyInfo)5 RemoteException (android.os.RemoteException)5 SynchronousResultReceiver (android.os.SynchronousResultReceiver)5 ModemActivityInfo (android.telephony.ModemActivityInfo)5