• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java BluetoothLeScannerCompat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



BluetoothLeScannerCompat类属于no.nordicsemi.android.support.v18.scanner包,在下文中一共展示了BluetoothLeScannerCompat类的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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ModuleChunk类代码示例发布时间:2022-05-22
下一篇:
Java ImageIOUtil类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap