当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothLeScannerCompat.getScanner方法代码示例

本文整理汇总了Java中no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat.getScanner方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothLeScannerCompat.getScanner方法的具体用法?Java BluetoothLeScannerCompat.getScanner怎么用?Java BluetoothLeScannerCompat.getScanner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat的用法示例。


在下文中一共展示了BluetoothLeScannerCompat.getScanner方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startLeScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
public void startLeScan() {
	// Scanning is disabled when we are connecting or connected.
	if (mConnectingPosition >= 0)
		return;

	if (mScanning) {
		// Extend scanning for some time more
		mHandler.removeCallbacks(mStopScanTask);
		mHandler.postDelayed(mStopScanTask, SCAN_DURATION);
		return;
	}

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	final ScanSettings settings = new ScanSettings.Builder().setReportDelay(1000).setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
	scanner.startScan(null, settings, mScanCallback);

	// Setup timer that will stop scanning
	mHandler.postDelayed(mStopScanTask, SCAN_DURATION);
	mScanning = true;
	notifyItemChanged(mDevices.size());
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:22,代码来源:DevicesAdapter.java

示例2: startScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * Start scanning for Bluetooth devices.
 */
public void startScan() {
	if (mScannerLiveData.isScanning()) {
		return;
	}

	// Scanning settings
	final ScanSettings settings = new ScanSettings.Builder()
			.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
			// Refresh the devices list every second
			.setReportDelay(0)
			// Hardware filtering has some issues on selected devices
			.setUseHardwareFilteringIfSupported(false)
			// Samsung S6 and S6 Edge report equal value of RSSI for all devices. In this app we ignore the RSSI.
				/*.setUseHardwareBatchingIfSupported(false)*/
			.build();

	// Let's use the filter to scan only for Blinky devices
	final ParcelUuid uuid = new ParcelUuid(BlinkyManager.LBS_UUID_SERVICE);
	final List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(uuid).build());

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	scanner.startScan(filters, settings, scanCallback);
	mScannerLiveData.scanningStarted();
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Blinky,代码行数:29,代码来源:ScannerViewModel.java

示例3: prepareForScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
private void prepareForScan(){
    if(isBleSupported()) {
        final ParcelUuid uuid = NODE_CONFIGURATION_SERVICE;
        mScanFilterList = new ArrayList<>();
        mScanFilterList.add(new ScanFilter.Builder().setServiceUuid(uuid).build());
        mScanner = BluetoothLeScannerCompat.getScanner();

        if (checkIfVersionIsMarshmallowOrAbove()) {
            startLocationModeChangeReceiver();
            connectToGoogleApiClient();
        } else {
            if (!isBleEnabled()) {
                final Intent bluetoothEnable = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(bluetoothEnable, REQUEST_ENABLE_BT);
            } else {
                startLeScan();
            }
        }
    } else {
        showError(getString(R.string.ble_not_supported), false);
    }
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-BLE-Joiner,代码行数:23,代码来源:MainActivity.java

示例4: stopLeScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
public void stopLeScan() {
	if (!mScanning)
		return;

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	scanner.stopScan(mScanCallback);

	mHandler.removeCallbacks(mStopScanTask);
	mScanning = false;
	notifyItemChanged(mDevices.size());
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:12,代码来源:DevicesAdapter.java

示例5: startScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback is activated This will perform regular scan for custom BLE Service UUID and then filter out.
 * using class ScannerServiceParser
 */
private void startScan() {
	// Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
	// Bluetooth LE devices. This is related to beacons as proximity devices.
	// On API older than Marshmallow the following code does nothing.
	if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
		// When user pressed Deny and still wants to use this functionality, show the rationale
		if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
			mPermissionRationale.setVisibility(View.VISIBLE);
			return;
		}

		requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_PERMISSION_REQ_CODE);
		return;
	}

	// Hide the rationale message, we don't need it anymore.
	if (mPermissionRationale != null)
		mPermissionRationale.setVisibility(View.GONE);

	mAdapter.clearDevices();
	mScanButton.setText(R.string.scanner_action_cancel);

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	final ScanSettings settings = new ScanSettings.Builder()
			.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(1000).setUseHardwareBatchingIfSupported(false).build();
	final List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(mUuid).build());
	scanner.startScan(filters, settings, scanCallback);

	mIsScanning = true;
	mHandler.postDelayed(new Runnable() {
		@Override
		public void run() {
			if (mIsScanning) {
				stopScan();
			}
		}
	}, SCAN_DURATION);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:44,代码来源:ScannerFragment.java

示例6: stopScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * Stop scan if user tap Cancel button
 */
private void stopScan() {
	if (mIsScanning) {
		mScanButton.setText(R.string.scanner_action_scan);

		final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
		scanner.stopScan(scanCallback);

		mIsScanning = false;
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:14,代码来源:ScannerFragment.java

示例7: startScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback is activated This will perform regular scan for custom BLE Service UUID and then filter out
 * using class ScannerServiceParser
 */
private void startScan() {
	// Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
	// Bluetooth LE devices. This is related to beacons as proximity devices.
	// On API older than Marshmallow the following code does nothing.
	if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
		// When user pressed Deny and still wants to use this functionality, show the rationale
		if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
			mPermissionRationale.setVisibility(View.VISIBLE);
			return;
		}

		requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_PERMISSION_REQ_CODE);
		return;
	}

	// Hide the rationale message, we don't need it anymore.
	if (mPermissionRationale != null)
		mPermissionRationale.setVisibility(View.GONE);

	mAdapter.clearDevices();
	mScanButton.setText(R.string.scanner_action_cancel);

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	final ScanSettings settings = new ScanSettings.Builder()
			.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(1000).setUseHardwareBatchingIfSupported(false).setUseHardwareFilteringIfSupported(false).build();
	final List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(mUuid).build());
	scanner.startScan(filters, settings, scanCallback);

	mIsScanning = true;
	mHandler.postDelayed(new Runnable() {
		@Override
		public void run() {
			if (mIsScanning) {
				stopScan();
			}
		}
	}, SCAN_DURATION);
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:44,代码来源:ScannerFragment.java

示例8: startScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * Scan for 5 seconds and then stop scanning when a BluetoothLE device is found then mLEScanCallback is activated This will perform regular scan for custom BLE Service UUID and then filter out.
 * using class ScannerServiceParser
 */
private void startScan() {
	// Since Android 6.0 we need to obtain either Manifest.permission.ACCESS_COARSE_LOCATION or Manifest.permission.ACCESS_FINE_LOCATION to be able to scan for
	// Bluetooth LE devices. This is related to beacons as proximity devices.
	// On API older than Marshmallow the following code does nothing.
	if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
		// When user pressed Deny and still wants to use this functionality, show the rationale
		if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) && mPermissionRationale.getVisibility() == View.GONE) {
			mPermissionRationale.setVisibility(View.VISIBLE);
			return;
		}

		requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, REQUEST_PERMISSION_REQ_CODE);
		return;
	}

	// Hide the rationale message, we don't need it anymore.
	if (mPermissionRationale != null)
		mPermissionRationale.setVisibility(View.GONE);

	mAdapter.clearDevices();
	mScanButton.setText(R.string.scanner_action_cancel);

	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	final ScanSettings settings = new ScanSettings.Builder()
			.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).setReportDelay(1000).setUseHardwareBatchingIfSupported(false).build();
	final List<ScanFilter> filters = new ArrayList<>();
	filters.add(new ScanFilter.Builder().setServiceUuid(mUuid).build());
	scanner.startScan(filters, settings, scanCallback);

	mIsScanning = true;
	mHandler.postDelayed(() -> {
		if (mIsScanning) {
			stopScan();
		}
	}, SCAN_DURATION);
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Toolbox,代码行数:41,代码来源:ScannerFragment.java

示例9: scanDevices

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
private void scanDevices() {

        Log.i(TAG, "scanDevices() mOwner " + mOwner);

        // Use this check to determine whether BLE is supported on the device.  Then you can
        // selectively disable BLE-related features.
        if (mOwner.getPackageManager() != null && !mOwner.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
            Log.e(TAG, "BT not supported; missing feature: " + PackageManager.FEATURE_BLUETOOTH_LE);
            // Toast.makeText(mOwner, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
            return;
        }

        // Initializes a Bluetooth adapter.  For API level 18 and above, get a reference to
        // BluetoothAdapter through BluetoothManager.
        BluetoothManager bluetoothManager =
                (BluetoothManager) mOwner.getSystemService(Context.BLUETOOTH_SERVICE);
        if (bluetoothManager == null) {
            Log.w(TAG, "BT not supported; BT service not available");
            Toast.makeText(mOwner, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
            return;
        }

        if (mBluetoothAdapter == null) {
            mBluetoothAdapter = bluetoothManager.getAdapter();
        }
        // Checks if Bluetooth is supported on the device.
        if (mBluetoothAdapter == null) {
            Log.w(TAG, "BT not supported; BT adapter not available");
            // Toast.makeText(mOwner, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
            return;
        }

        // If requesting only BT devices, check for BT on
        if (!mBluetoothAdapter.isEnabled())
        {
            Log.w(TAG, "BT not ON");
            Toast.makeText(mOwner, R.string.text_bt_not_on, Toast.LENGTH_LONG).show();
            return;
        }

        // Location ON is required for android M or newer
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !isLocationServicesEnabled())
        {
            Log.w(TAG, "Location not ON; BT search not available");
            Toast.makeText(mOwner, R.string.text_location_not_on, Toast.LENGTH_LONG).show();
            // return; // Do not return, it might still work.. some xiaomi miui8 phones for example
        }

        if (mScanner == null)
            mScanner = BluetoothLeScannerCompat.getScanner();

        onScanStarted();
    }
 
开发者ID:NordicID,项目名称:nur_sample_android,代码行数:54,代码来源:BleScanner.java

示例10: stopScan

import no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat; //导入方法依赖的package包/类
/**
 * stop scanning for bluetooth devices.
 */
public void stopScan() {
	final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
	scanner.stopScan(scanCallback);
	mScannerLiveData.scanningStopped();
}
 
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Blinky,代码行数:9,代码来源:ScannerViewModel.java


注:本文中的no.nordicsemi.android.support.v18.scanner.BluetoothLeScannerCompat.getScanner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。