本文整理汇总了Java中android.bluetooth.le.ScanSettings.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ScanSettings.Builder方法的具体用法?Java ScanSettings.Builder怎么用?Java ScanSettings.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.le.ScanSettings
的用法示例。
在下文中一共展示了ScanSettings.Builder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildSettings
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Deprecated
static ScanSettings.Builder buildSettings(BleManager mgr, int scanMode, Interval scanReportDelay) {
final ScanSettings.Builder builder = new ScanSettings.Builder();
builder.setScanMode(scanMode);
if( mgr.getNativeAdapter().isOffloadedScanBatchingSupported() )
{
final long scanReportDelay_millis = false == Interval.isDisabled(scanReportDelay) ? scanReportDelay.millis() : 0;
builder.setReportDelay(scanReportDelay_millis);
}
else
{
builder.setReportDelay(0);
}
return builder;
}
示例2: scanDevice
import android.bluetooth.le.ScanSettings; //导入方法依赖的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);
}
示例3: RuuviTagScanner
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
public RuuviTagScanner(RuuviTagListener listener, Context context) {
this.listener = listener;
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
if (useNewApi()) {
bleScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
scanSettings = scanSettingsBuilder.build();
}
}
示例4: onCreate
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setTitle(com.igrow.android.R.string.title_devices);
mHandler = new Handler();
// Use this check to determine whether BLE is supported on the device. Then you can
// selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, com.igrow.android.R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
finish();
}
// Initializes a Bluetooth adapter. For API level 18 and above, get a reference to
// BluetoothAdapter through BluetoothManager.
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// Checks if Bluetooth is supported on the device.
if (mBluetoothAdapter == null) {
Toast.makeText(this, com.igrow.android.R.string.error_bluetooth_not_supported, Toast.LENGTH_SHORT).show();
finish();
return;
}
if (android.os.Build.VERSION.SDK_INT >= 21) {
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
mScanSettings = scanSettingsBuilder.build();
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
}
}
示例5: buildScanSettings
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
private ScanSettings buildScanSettings() {
ScanSettings.Builder builder = new ScanSettings.Builder();
builder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER);
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE);
builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT);
builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
}
return builder.build();
}
示例6: createScanSettings
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
private ScanSettings createScanSettings() {
ScanSettings.Builder builder = new ScanSettings.Builder();
ScanSettings settings;
builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE);
builder.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT);
settings = builder.build();
return settings;
}
示例7: startNativeScan
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Deprecated
public static void startNativeScan(BleManager mgr, int scanMode, Interval scanReportDelay, L_Util.ScanCallback listener) {
final ScanSettings.Builder builder = L_Util.buildSettings(mgr, scanMode, scanReportDelay);
builder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
builder.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE);
builder.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT);
final ScanSettings scanSettings = builder.build();
L_Util.startScan(mgr, scanSettings, listener);
}
示例8: startScan
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
private void startScan() {
BluetoothLeScanner bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanFilter.Builder builder = new ScanFilter.Builder();
Vector<ScanFilter> filter = new Vector<ScanFilter>();
filter.add(builder.build());
ScanSettings.Builder builderScanSettings = new ScanSettings.Builder();
builderScanSettings.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
builderScanSettings.setReportDelay(0);
bluetoothScanner.startScan(filter, builderScanSettings.build(), leScanCallback);
}
示例9: getScanSettings
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static ScanSettings getScanSettings()
{
final ScanSettings.Builder builder = new ScanSettings.Builder();
builder.setReportDelay(0);
builder.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER);
return builder.build();
}
示例10: call
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Override
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
public void call(Subscriber<? super List<GattPeripheral>> subscriber) {
logger.info(BluetoothStack.LOG_TAG, "Beginning Scan (Lollipop impl)");
this.subscriber = subscriber;
if (scanner != null) {
this.scanning = true;
// Guards against the checking the power state of the BluetoothAdapter,
// then the power state changing between that check and the following
// call to startScan.
try {
final ScanSettings.Builder builder = new ScanSettings.Builder();
builder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
scanner.startScan(null, builder.build(), this);
} catch (IllegalStateException e) {
this.scanning = false;
subscriber.onError(new UserDisabledBuruberiException(e));
return;
}
this.timeout = stack.getScheduler()
.createWorker()
.schedule(new Action0() {
@Override
public void call() {
onConcludeScan();
}
}, peripheralCriteria.duration, TimeUnit.MILLISECONDS);
} else {
subscriber.onError(new UserDisabledBuruberiException());
}
}
示例11: Ble
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
public Ble(Context c, BleListener i, String deviceUuid, String r, String t)
{
context = c;
iface = i;
superPanelUuid = ParcelUuid.fromString(deviceUuid);
rxUUid = UUID.fromString(r);
txUUid = UUID.fromString(t);
adapter = BluetoothAdapter.getDefaultAdapter();
scanner = adapter.getBluetoothLeScanner();
ScanFilter.Builder filter = new ScanFilter.Builder();
filter.setServiceUuid(superPanelUuid);
ScanFilter.Builder superPanelFilter = new ScanFilter.Builder();
superPanelFilter.setServiceUuid(superPanelUuid);
ScanSettings.Builder settings = new ScanSettings.Builder();
settings.setScanMode(ScanSettings.SCAN_MODE_LOW_POWER);
List<ScanFilter> filters = new ArrayList<ScanFilter>();
filters.add(filter.build());
//filters.add(superPanelFilter.build());
if(scanner == null)
{
System.out.println("Failed to get LE scanner");
return;
}
scanner.startScan(filters, settings.build(), scanCallback);
}
示例12: onReceive
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
PowerManager powerManager = (PowerManager) context.getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
Log.d(TAG, "Woke up");
final BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
if (useNewApi()) {
bleScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
scanSettings = scanSettingsBuilder.build();
}
scanResults = new ArrayList<LeScanResult>();
//MainActivity.enableBluetooth();
if (!canScan()) {
Log.d(TAG, "Could not start scanning in background, scheduling next attempt");
scheduleNextScan(context);
return;
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (useNewApi()) {
bleScanner.stopScan(bleScannerCallback);
} else {
bluetoothAdapter.stopLeScan(mLeScanCallback);
}
processFoundDevices(context);
scanResults = new ArrayList<LeScanResult>();
}
}, SCAN_TIME_MS);
if (useNewApi()) {
bleScanner.startScan(scanFilters, scanSettings, bleScannerCallback);
} else {
bluetoothAdapter.startLeScan(mLeScanCallback);
}
}
示例13: onCreate
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
settings = PreferenceManager.getDefaultSharedPreferences(this);
settings.registerOnSharedPreferenceChangeListener(mListener);
notificationId = 1512;
if (settings.getBoolean("pref_bgscan", false))
startFG();
Foreground.init(getApplication());
Foreground.get().addListener(listener);
ruuviTagArrayList = new ArrayList<>();
backendUrl = settings.getString("pref_backend", null);
scanTimerHandler = new Handler();
scanResults = new ArrayList<LeScanResult>();
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
bluetoothAdapter = bluetoothManager.getAdapter();
if (useNewApi()) {
bleScanner = bluetoothAdapter.getBluetoothLeScanner();
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
scanSettings = scanSettingsBuilder.build();
}
scheduler = Executors.newSingleThreadScheduledExecutor();
int scanInterval = Integer.parseInt(settings.getString("pref_scaninterval", "5")) * 1000;
if (scanInterval <= MAX_SCAN_TIME_MS) scanInterval = MAX_SCAN_TIME_MS + 100;
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
if (!scheduler.isShutdown())
startScan();
}
}, 0, scanInterval, TimeUnit.MILLISECONDS);
timer = new Timer();
TimerTask alertManager = new ScannerService.alertManager();
timer.scheduleAtFixedRate(alertManager, 2500, 2500);
}
示例14: scan
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@Override
public void scan(ReadableArray serviceUUIDs, final int scanSeconds, ReadableMap options, Callback callback) {
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
List<ScanFilter> filters = new ArrayList<>();
scanSettingsBuilder.setScanMode(options.getInt("scanMode"));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
scanSettingsBuilder.setNumOfMatches(options.getInt("numberOfMatches"));
scanSettingsBuilder.setMatchMode(options.getInt("matchMode"));
}
if (serviceUUIDs.size() > 0) {
for(int i = 0; i < serviceUUIDs.size(); i++){
ScanFilter filter = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(UUIDHelper.uuidFromString(serviceUUIDs.getString(i)))).build();
filters.add(filter);
Log.d(bleManager.LOG_TAG, "Filter service: " + serviceUUIDs.getString(i));
}
}
getBluetoothAdapter().getBluetoothLeScanner().startScan(filters, scanSettingsBuilder.build(), mScanCallback);
if (scanSeconds > 0) {
Thread thread = new Thread() {
private int currentScanSession = scanSessionId.incrementAndGet();
@Override
public void run() {
try {
Thread.sleep(scanSeconds * 1000);
} catch (InterruptedException ignored) {
}
runOnUiThread(new Runnable() {
@Override
public void run() {
BluetoothAdapter btAdapter = getBluetoothAdapter();
// check current scan session was not stopped
if (scanSessionId.intValue() == currentScanSession) {
if(btAdapter.getState() == BluetoothAdapter.STATE_ON) {
btAdapter.getBluetoothLeScanner().stopScan(mScanCallback);
}
WritableMap map = Arguments.createMap();
bleManager.sendEvent("BleManagerStopScan", map);
}
}
});
}
};
thread.start();
}
callback.invoke();
}
示例15: convertCompatScanSettingsToNative
import android.bluetooth.le.ScanSettings; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static ScanSettings convertCompatScanSettingsToNative(com.taptrack.tcmptappy.blescannercompat.ScanSettings compatSettings) {
if(compatSettings == null)
return null;
ScanSettings.Builder nativeBuilder = new ScanSettings.Builder();
nativeBuilder = nativeBuilder.setReportDelay(compatSettings.getReportDelayMillis());
switch (compatSettings.getScanMode()) {
case com.taptrack.tcmptappy.blescannercompat.ScanSettings.SCAN_MODE_BALANCED: {
nativeBuilder = nativeBuilder.setScanMode(ScanSettings.SCAN_MODE_BALANCED);
break;
}
case com.taptrack.tcmptappy.blescannercompat.ScanSettings.SCAN_MODE_LOW_LATENCY: {
nativeBuilder = nativeBuilder.setScanMode(ScanSettings.SCAN_MODE_BALANCED);
break;
}
default:
case com.taptrack.tcmptappy.blescannercompat.ScanSettings.SCAN_MODE_LOW_POWER: {
nativeBuilder = nativeBuilder.setScanMode(ScanSettings.SCAN_MODE_BALANCED);
break;
}
}
// Only in marshmallow
// switch (compatSettings.getCallbackType()) {
// case ScanSettings.CALLBACK_TYPE_MATCH_LOST: {
// nativeBuilder = nativeBuilder.setCallbackType(ScanSettings.CALLBACK_TYPE_MATCH_LOST);
// break;
// }
// case ScanSettings.CALLBACK_TYPE_FIRST_MATCH: {
// nativeBuilder = nativeBuilder.setCallbackType(ScanSettings.CALLBACK_TYPE_FIRST_MATCH);
// break;
// }
// default:
// case ScanSettings.CALLBACK_TYPE_ALL_MATCHES: {
// nativeBuilder = nativeBuilder.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES);
// break;
// }
// }
return nativeBuilder.build();
}