當前位置: 首頁>>代碼示例>>Java>>正文


Java BluetoothLeScanner類代碼示例

本文整理匯總了Java中android.bluetooth.le.BluetoothLeScanner的典型用法代碼示例。如果您正苦於以下問題:Java BluetoothLeScanner類的具體用法?Java BluetoothLeScanner怎麽用?Java BluetoothLeScanner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BluetoothLeScanner類屬於android.bluetooth.le包,在下文中一共展示了BluetoothLeScanner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: scanDevice

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
protected static void scanDevice(BluetoothAdapter bluetoothAdapter, U2FBLEDeviceNotification notification, Logger logger, Context context, String data, ScanType scanType) {
	BluetoothLeScanner bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner();
	ScanFilter.Builder builder = new ScanFilter.Builder();
	switch(scanType) {
		case SCAN_BY_NAME:
			builder.setDeviceName(data);
			break;
	}
	Vector<ScanFilter> filter = new Vector<ScanFilter>();
	filter.add(builder.build());
	ScanSettings.Builder builderScanSettings = new ScanSettings.Builder();
	builderScanSettings.setScanMode(ScanSettings.SCAN_MODE_BALANCED);
	builderScanSettings.setReportDelay(0);
	LocalScanCallback scannerCallback = new LocalScanCallback(bluetoothAdapter, logger, notification, context);
	bluetoothScanner.startScan(filter, builderScanSettings.build(), scannerCallback);		
}
 
開發者ID:LedgerHQ,項目名稱:u2f-ble-test,代碼行數:17,代碼來源:U2FBLEDevice.java

示例2: stopScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
/**
 * Stops scanning for devices
 *
 * @return An Observable which emits ScanResult
 */
public Observable<ScanResult> stopScan() {
    return Observable.create(subscriber -> {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
            if (scanner != null) {
                scanner.stopScan(getScanCallback(subscriber));
            } else {
                Log.e(TAG, "BluetoothLeScanner is null");
                subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
            }
        } else {
            Log.e(TAG, "BluetoothAdapter is null");
            subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
        }
    });
}
 
開發者ID:dkhmelenko,項目名稱:miband-android,代碼行數:23,代碼來源:MiBand.java

示例3: startDiscoveringBle

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
private boolean startDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ startDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "startDiscoveringBle() : Already in classic discovering mode");
		return true;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "startDiscoveringBle() : Choose startScan()");
		mLeScanner = mAdapter.getBluetoothLeScanner();
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).startScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.startScan(mScanCallback); ???
	} else {
		Log.i(TAG, "startDiscoveringBle() : Choose startLeScan()");
		return mAdapter.startLeScan(mLeScanCallback);
	}
	return true;
}
 
開發者ID:BohanLu,項目名稱:NobleAries,代碼行數:27,代碼來源:Chores.java

示例4: stopScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@Override
public void stopScan(@NonNull ScanCallback callback) {
    ScanCallbackHolder holder = callbackHolderMap.get(callback);
    if(holder == null) //possibly should throw an exception...
        return;

    BluetoothLeScanner scanner = getNativeScannerOrThrow();

    scanner.stopScan(holder.getNativeCallback());
    callbackHolderMap.remove(callback);
}
 
開發者ID:TapTrack,項目名稱:TappyBLE,代碼行數:12,代碼來源:LollipopBleScanner.java

示例5: startScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
/**
 * Starts scanning for devices
 *
 * @return An Observable which emits ScanResult
 */
public Observable<ScanResult> startScan() {
    return Observable.create(subscriber -> {
        BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
        if (adapter != null) {
            BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
            if (scanner != null) {
                scanner.startScan(getScanCallback(subscriber));
            } else {
                Log.e(TAG, "BluetoothLeScanner is null");
                subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
            }
        } else {
            Log.e(TAG, "BluetoothAdapter is null");
            subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
        }
    });
}
 
開發者ID:dkhmelenko,項目名稱:miband-android,代碼行數:23,代碼來源:MiBand.java

示例6: cancelDiscoveringBle

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
private boolean cancelDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ cancelDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "cancelDiscoveringBle() : In classic discovering mode");
		return false;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopScan()");
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).stopScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.stopScan(mScanCallback); ???
	} else {
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopLeScan()");
		mAdapter.stopLeScan(mLeScanCallback);
	}
	return true;
}
 
開發者ID:BohanLu,項目名稱:NobleAries,代碼行數:26,代碼來源:Chores.java

示例7: stopScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@Override
public void stopScan(final ScanCallback callback) {
	final ScanCallbackWrapper wrapper = mWrappers.get(callback);
	if (wrapper == null)
		return;

	wrapper.close();
	mWrappers.remove(callback);
	android.bluetooth.le.ScanCallback _callback = mCallbacks.get(callback);
	mCallbacks.remove(callback);
	mWrappers2.remove(_callback);

	final BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
	if (scanner == null)
		return;

	scanner.stopScan(_callback);
}
 
開發者ID:NordicSemiconductor,項目名稱:Android-Scanner-Compat-Library,代碼行數:19,代碼來源:BluetoothLeScannerImplLollipop.java

示例8: startScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
public static void startScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.startScan(callback);
}
 
開發者ID:pangliang,項目名稱:miband-sdk-android,代碼行數:14,代碼來源:MiBand.java

示例9: stopScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
public static void stopScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.stopScan(callback);
}
 
開發者ID:pangliang,項目名稱:miband-sdk-android,代碼行數:14,代碼來源:MiBand.java

示例10: stopAndroidOBackgroundScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.O)
void stopAndroidOBackgroundScan() {
    try {
        final BluetoothManager bluetoothManager =
                (BluetoothManager) mContext.getApplicationContext().getSystemService(Context.BLUETOOTH_SERVICE);
        BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
        if (bluetoothAdapter == null) {
            LogManager.w(TAG, "Failed to construct a BluetoothAdapter");
        } else if (!bluetoothAdapter.isEnabled()) {
            LogManager.w(TAG, "BluetoothAdapter is not enabled");
        } else {
           BluetoothLeScanner scanner =  bluetoothAdapter.getBluetoothLeScanner();
           if (scanner != null) {
               scanner.stopScan(getScanCallbackIntent());
           }
        }
    } catch (SecurityException e) {
        LogManager.e(TAG, "SecurityException stopping Android O background scanner");
    }
}
 
開發者ID:AltBeacon,項目名稱:android-beacon-library,代碼行數:21,代碼來源:ScanHelper.java

示例11: getScanner

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
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;
}
 
開發者ID:AltBeacon,項目名稱:android-beacon-library,代碼行數:19,代碼來源:CycledLeScannerForLollipop.java

示例12: startListeningBluetoothMeasurements

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void startListeningBluetoothMeasurements(List<ScanFilter> scanFilters,
                                                 ScanSettings scanSettings,
                                                 ScanCallback scanCallback){
    BluetoothLeScanner scanner = bluetoothManager.getAdapter().getBluetoothLeScanner();
    scanner.startScan(scanFilters, scanSettings, scanCallback);
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:8,代碼來源:BLEMeasurementsGatherer.java

示例13: addUnsuscribeCallbackFor

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void addUnsuscribeCallbackFor(FlowableEmitter<SensorRecord> subscriber,
                                      final ScanCallback scanCallback){
    final BluetoothLeScanner scanner = bluetoothManager.getAdapter().getBluetoothLeScanner();
    subscriber.setCancellable(new Cancellable() {
        @Override
        public void cancel() throws Exception {
            scanner.flushPendingScanResults(scanCallback);
            scanner.stopScan(scanCallback);
        }
    });
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:13,代碼來源:BLEMeasurementsGatherer.java

示例14: pause

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
private void pause() {
  if (bluetoothAdapter != null) {
    BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
    if (scanner != null && scanCallback != null) {
      scanner.stopScan(scanCallback);
    }
  }
}
 
開發者ID:drfonfon,項目名稱:ITagAntiLost,代碼行數:9,代碼來源:NewDevicePresenter.java

示例15: stopLeScan

import android.bluetooth.le.BluetoothLeScanner; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void stopLeScan(ScanCallback scanCallback) {
    final BluetoothLeScanner bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
    if (bluetoothLeScanner == null) {
        RxBleLog.d("Cannot perform BluetoothLeScanner.stopScan(ScanCallback) because scanner is unavailable (Probably adapter is off)");
        // if stopping the scan is not possible due to BluetoothLeScanner not accessible then it is probably stopped anyway
        return;
    }
    bluetoothLeScanner.stopScan(scanCallback);
}
 
開發者ID:Polidea,項目名稱:RxAndroidBle,代碼行數:11,代碼來源:RxBleAdapterWrapper.java


注:本文中的android.bluetooth.le.BluetoothLeScanner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。