當前位置: 首頁>>代碼示例>>Java>>正文


Java ScanResult.getScanRecord方法代碼示例

本文整理匯總了Java中android.bluetooth.le.ScanResult.getScanRecord方法的典型用法代碼示例。如果您正苦於以下問題:Java ScanResult.getScanRecord方法的具體用法?Java ScanResult.getScanRecord怎麽用?Java ScanResult.getScanRecord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.bluetooth.le.ScanResult的用法示例。


在下文中一共展示了ScanResult.getScanRecord方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@Override
public void onScanResult(int callbackType, ScanResult result) {
  super.onScanResult(callbackType, result);
  if (result.getScanRecord() != null) {
    List<ParcelUuid> uuids = result.getScanRecord().getServiceUuids();
    if (uuids != null) {
      for (ParcelUuid uuid : uuids) {
        if (uuid.getUuid().equals(BleService.FIND_ME_SERVICE)) {
          if (!currentAddresses.contains(result.getDevice().getAddress()))
            viewStatePublisher.onNext(
                new NewDevicesViewState.NewDeviceState(
                    result.getDevice().getAddress(),
                    result.getScanRecord().getDeviceName())
            );
          break;
        }
      }
    }
  }
}
 
開發者ID:drfonfon,項目名稱:ITagAntiLost,代碼行數:21,代碼來源:NewDevicePresenter.java

示例2: convertBleDevice

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BleDevice convertBleDevice(ScanResult scanResult) {
    if (scanResult == null) {
        throw new IllegalArgumentException("scanResult can not be Null!");
    }
    BluetoothDevice bluetoothDevice = scanResult.getDevice();
    int rssi = scanResult.getRssi();
    ScanRecord scanRecord = scanResult.getScanRecord();
    byte[] bytes = null;
    if (scanRecord != null)
        bytes = scanRecord.getBytes();
    long timestampNanos = scanResult.getTimestampNanos();
    return new BleDevice(bluetoothDevice, rssi, bytes, timestampNanos);
}
 
開發者ID:Jasonchenlijian,項目名稱:FastBle,代碼行數:15,代碼來源:BleManager.java

示例3: ScanResultCompat

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanResultCompat(ScanResult result) {
    mDevice = result.getDevice();
    mScanRecord = new ScanRecordCompat(result.getScanRecord());
    mRssi = result.getRssi();
    mTimestampNanos = result.getTimestampNanos();
}
 
開發者ID:joerogers,項目名稱:BluetoothCompat,代碼行數:8,代碼來源:ScanResultCompat.java

示例4: beaconFromScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
protected static Beacon beaconFromScanResult(ScanResult scanResult) {
    ScanRecord scanRecord = scanResult.getScanRecord();
    if (scanRecord == null) {
        return null;
    }
    FrameType type;
    Integer txPower;
    double rssi = scanResult.getRssi();
    byte[] bytes = scanRecord.getServiceData(EDDYSTONE_SPEC);
    String identifier = scanResult.getDevice().getAddress();

    txPower = txPowerFromBytes(bytes);

    if (txPower != null) {
        Beacon beacon = new Beacon(rssi, txPower, identifier);
        beacon.parseScanResult(scanResult);
        return beacon;
    }

    return null;
}
 
開發者ID:BlueBiteLLC,項目名稱:eddystone-android,代碼行數:22,代碼來源:Beacon.java

示例5: processResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
private void processResult(ScanResult result) {
    ScanRecord record = result.getScanRecord();
    if (record == null || record.getServiceData(UID_SERVICE) == null) {
        Log.w(TAG, "Invalid Eddystone scan result.");
        return;
    }

    //Convert scan result into an AdvertisedId
    Beacon.AdvertisedId advertisedId =
            Beacon.AdvertisedId.fromAdvertisement(record.getServiceData(UID_SERVICE));
    final Beacon discovered = new Beacon(advertisedId, Beacon.Status.STATUS_UNSPECIFIED);
    //Scan callbacks are not on the main thread
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            //Notify the adapter, and get beacon resource from API
            boolean added = mAdapter.addDiscoveredBeacon(discovered);
            if (added) {
                mProximityApi.getBeacon(discovered.advertisedId);
            }
        }
    });
}
 
開發者ID:devunwired,項目名稱:proximity-manager,代碼行數:24,代碼來源:BeaconRegisterActivity.java

示例6: createCallback

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
private static android.bluetooth.le.ScanCallback createCallback(ScanCallback scanCallback) {
    return new android.bluetooth.le.ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {

            BluetoothDevice device = result.getDevice();
            int rssi = result.getRssi();
            byte[] scanRecord = (result.getScanRecord() != null ? result.getScanRecord().getBytes() : null);
            scanCallback.onDeviceFound(device, rssi, scanRecord);

            super.onScanResult(callbackType, result);
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };
}
 
開發者ID:devicehive,項目名稱:android-ble,代碼行數:25,代碼來源:BleScannerL.java

示例7: onScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
/**
 * Callback when a BLE advertisement has been found.
 *
 * @param callbackType Determines how this callback was triggered.
 * @param result       A Bluetooth LE scan result.
 */
@Override
public void onScanResult(int callbackType, final ScanResult result) {
    super.onScanResult(callbackType, result);

    // Get the ScanRecord and check if it is defined (is nullable)
    final ScanRecord scanRecord = result.getScanRecord();
    if (scanRecord != null) {
        // Check if the Service UUIDs are defined (is nullable) and contain the discovery
        // UUID
        final List<ParcelUuid> serviceUuids = scanRecord.getServiceUuids();
        if (serviceUuids != null && serviceUuids.contains(DISCOVERY_UUID)) {
            // We have found our device, so update the GUI, stop scanning and start
            // connecting
            final BluetoothDevice device = result.getDevice();

            // We'll make sure the GUI is updated on the UI thread
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // At this point we have the device address and RSSI, so update those
                    deviceAddressTextView.setText(device.getAddress());
                    rssiTextView.setText(getString(R.string.rssi, result.getRssi()));
                }
            });

            stopDiscovery();

            bluetoothGatt = device.connectGatt(
                    MainActivity.this,
                    // False here, as we want to directly connect to the device
                    false,
                    bluetoothGattCallback
            );
        }
    }
}
 
開發者ID:SPINremote,項目名稱:sdc-1-quickstart-android,代碼行數:43,代碼來源:MainActivity.java

示例8: ScanResultCompat

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanResultCompat(ScanResult result) {
    mDevice = new BluetoothLeDevice(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes(), System.currentTimeMillis());//result.getTimestampNanos()
    mScanRecord = new ScanRecordCompat(result.getScanRecord());
    mRssi = result.getRssi();
    mTimestampNanos = System.currentTimeMillis();//result.getTimestampNanos();
}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:8,代碼來源:ScanResultCompat.java

示例9: initScanData

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
private void initScanData() {
    scanCallback = new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            super.onScanResult(callbackType, result);
            Log.i(TAG, "onScanResult" + result);
            String address = result.getDevice().getAddress();
            String name;
            ScanRecord scanRecord = result.getScanRecord();
            name = scanRecord == null ? "unknown" : scanRecord.getDeviceName();
            scanResultListener.onResultReceived(name, address);
        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
            Log.e(TAG, "onBatchScanResults");
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
            Log.e(TAG, "onScanFailed");
            scanResultListener.onScanFailed(errorCode);
        }
    };
    filters = new ArrayList<>();
    filters.add(new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(BLEProfile.UUID_SERVICE)).build());
    scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
}
 
開發者ID:czvn,項目名稱:Android-BLE-Library,代碼行數:31,代碼來源:BLEScanner.java

示例10: processResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
private void processResult(ScanResult result) {
    Log.i(TAG, "New LE Device: " + result.getDevice().getName() + " @ " + result.getRssi());

    /*
     * Create a new beacon from the list of obtains AD structures
     * and pass it up to the main thread
     */
    TemperatureBeacon beacon = new TemperatureBeacon(result.getScanRecord(),
            result.getDevice().getAddress(),
            result.getRssi());
    mHandler.sendMessage(Message.obtain(null, 0, beacon));
}
 
開發者ID:ruipoliveira,項目名稱:livingCity-Android,代碼行數:13,代碼來源:BeaconLollipopActivity.java

示例11: onScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@Override
public void onScanResult(int callbackType, ScanResult result) {
    super.onScanResult(callbackType, result);
    BleLog.i(TAG, "onScanResult: " + callbackType + " ScanResult:" + result);
    if (result.getScanRecord() != null) {
        mScanCallback.onBleScan(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());
    }
}
 
開發者ID:captain-miao,項目名稱:bleYan,代碼行數:9,代碼來源:LollipopBleScanner.java

示例12: onScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@Override
@RequiresPermission(allOf = {
        Manifest.permission.BLUETOOTH,
        Manifest.permission.BLUETOOTH_ADMIN,
})
public void onScanResult(int callbackType, ScanResult result) {
    if (result.getScanRecord() == null) {
        return;
    }

    BluetoothDevice device = result.getDevice();
    String address = device.getAddress();
    ScannedPeripheral existingResult = results.get(address);
    if (existingResult != null) {
        existingResult.rssi = result.getRssi();
        return;
    }

    byte[] scanResponse = result.getScanRecord().getBytes();
    AdvertisingData advertisingData = AdvertisingData.parse(scanResponse);
    logger.info(BluetoothStack.LOG_TAG, "Found device " + device.getName() + " - " + address + " " + advertisingData);

    if (!peripheralCriteria.matches(advertisingData)) {
        return;
    }

    if (hasAddresses && !peripheralCriteria.peripheralAddresses.contains(address)) {
        return;
    }

    results.put(address, new ScannedPeripheral(device, advertisingData, result.getRssi()));

    if (results.size() >= peripheralCriteria.limit) {
        logger.info(BluetoothStack.LOG_TAG, "Discovery limit reached, concluding scan");
        onConcludeScan();
    }
}
 
開發者ID:hello,項目名稱:android-buruberi,代碼行數:38,代碼來源:LollipopLePeripheralScanner.java

示例13: processResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
private void processResult(ScanResult result) {
    ScanRecord record = result.getScanRecord();
    if (record == null) {
        Log.w(TAG, "Invalid scan record.");
        return;
    }
    final byte[] data = record.getServiceData(UID_SERVICE);
    if (data == null) {
        Log.w(TAG, "Invalid Eddystone scan result.");
        return;
    }

    final String deviceAddress = result.getDevice().getAddress();
    final int rssi = result.getRssi();
    byte frameType = data[0];
    switch (frameType) {
        case TYPE_UID:
            mCallbackHandler.post(new Runnable() {
                @Override
                public void run() {
                    processUidPacket(deviceAddress, rssi, data);
                }
            });
            break;
        case TYPE_TLM:
        case TYPE_URL:
            //Do nothing, ignoring these
            return;
        default:
            Log.w(TAG, "Invalid Eddystone scan result.");
    }
}
 
開發者ID:devunwired,項目名稱:nearby-beacons,代碼行數:33,代碼來源:EddystoneScannerService.java

示例14: onScanResult

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
@Override
public void onScanResult(int callbackType, ScanResult result) {
    super.onScanResult(callbackType, result);
    ScanRecord record = result.getScanRecord();
    if(record!=null)
        mCallbackPre21.onLeScan(result.getDevice(),result.getRssi(),record.getBytes());
}
 
開發者ID:STMicroelectronics-CentralLabs,項目名稱:BlueSTSDK_Android,代碼行數:8,代碼來源:ScanCallbackBridge.java

示例15: BLEScanner

import android.bluetooth.le.ScanResult; //導入方法依賴的package包/類
public BLEScanner(final Activity activity, int requestEnableBluetooth, @NonNull OnClosestChangedListener onClosestChangedListener) {
    mRequestEnableBluetooth = requestEnableBluetooth;
    mOnClosestChangedListener = onClosestChangedListener;
    init(activity);
    scanFilters = new ArrayList<>();
    scanFilters.add(new ScanFilter.Builder().setServiceUuid(EDDYSTONE_SERVICE_UUID).build());
    scanCallback = new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            ScanRecord scanRecord = result.getScanRecord();
            if (scanRecord == null) {
                return;
            }

            String deviceAddress = result.getDevice().getAddress();
            Beacon beacon;
            if (!deviceToBeaconMap.containsKey(deviceAddress)) {
                beacon = new Beacon(deviceAddress, result.getRssi());
                deviceToBeaconMap.put(deviceAddress, beacon);
            } else {
                deviceToBeaconMap.get(deviceAddress).lastSeenTimestamp = System.currentTimeMillis();
                deviceToBeaconMap.get(deviceAddress).rssi = result.getRssi();
            }

            byte[] serviceData = scanRecord.getServiceData(EDDYSTONE_SERVICE_UUID);
            validateServiceData(deviceAddress, serviceData);

            findClosest();
        }

        @Override
        public void onScanFailed(int errorCode) {
            switch (errorCode) {
                case SCAN_FAILED_ALREADY_STARTED:
                    logErrorAndShowToast(activity, "SCAN_FAILED_ALREADY_STARTED");
                    break;
                case SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
                    logErrorAndShowToast(activity, "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED");
                    break;
                case SCAN_FAILED_FEATURE_UNSUPPORTED:
                    logErrorAndShowToast(activity, "SCAN_FAILED_FEATURE_UNSUPPORTED");
                    break;
                case SCAN_FAILED_INTERNAL_ERROR:
                    logErrorAndShowToast(activity, "SCAN_FAILED_INTERNAL_ERROR");
                    break;
                default:
                    logErrorAndShowToast(activity, "Scan failed, unknown error code");
                    break;
            }
        }
    };
}
 
開發者ID:etsy,項目名稱:divertsy-client,代碼行數:53,代碼來源:BLEScanner.java


注:本文中的android.bluetooth.le.ScanResult.getScanRecord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。