當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。