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


Java ScanSettings.Builder方法代码示例

本文整理汇总了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;
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:17,代码来源:L_Util.java

示例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);		
}
 
开发者ID:LedgerHQ,项目名称:u2f-ble-test,代码行数:17,代码来源:U2FBLEDevice.java

示例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();
    }
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:12,代码来源:RuuviTagScanner.java

示例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();
    }
}
 
开发者ID:igrow-systems,项目名称:igrow-android,代码行数:35,代码来源:DeviceScanActivity.java

示例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();
}
 
开发者ID:aarmea,项目名称:noise,代码行数:13,代码来源:BluetoothSyncService.java

示例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;
}
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:12,代码来源:JniCallbacks.java

示例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);
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:13,代码来源:M_Util.java

示例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);
}
 
开发者ID:LedgerHQ,项目名称:u2f-ble-test,代码行数:11,代码来源:MainActivity.java

示例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();
}
 
开发者ID:inthepocket,项目名称:ibeacon-scanner-android,代码行数:9,代码来源:DefaultScanService.java

示例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());
    }
}
 
开发者ID:hello,项目名称:android-buruberi,代码行数:37,代码来源:LollipopLePeripheralScanner.java

示例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);
}
 
开发者ID:tripzero,项目名称:SuperPanel,代码行数:32,代码来源:Ble.java

示例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);
    }
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:45,代码来源:BackgroundScanner.java

示例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);
}
 
开发者ID:ruuvi,项目名称:com.ruuvi.station,代码行数:45,代码来源:ScannerService.java

示例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();
}
 
开发者ID:innoveit,项目名称:react-native-ble-manager,代码行数:56,代码来源:LollipopScanManager.java

示例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();
    }
 
开发者ID:TapTrack,项目名称:TappyBLE,代码行数:44,代码来源:LollipopUtils.java


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