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


Java ScanRecord类代码示例

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


ScanRecord类属于android.bluetooth.le包,在下文中一共展示了ScanRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertBleDevice

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例2: beaconFromScanResult

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例3: processResult

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例4: onScanResult

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例5: ScanRecordCompat

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
ScanRecordCompat(ScanRecord record) {
    mServiceUuids = record.getServiceUuids();
    mManufacturerSpecificData = record.getManufacturerSpecificData();
    mServiceData = record.getServiceData();
    mDeviceName = record.getDeviceName();
    mAdvertiseFlags = record.getAdvertiseFlags();
    mTxPowerLevel = record.getTxPowerLevel();
    mBytes = record.getBytes();
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:11,代码来源:ScanRecordCompat.java

示例6: initScanData

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例7: TemperatureBeacon

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public TemperatureBeacon(ScanRecord record, String deviceAddress, int rssi) {
    mSignal = rssi;
    mAddress = deviceAddress;

    mName = record.getDeviceName();

    byte[] data = record.getServiceData(THERM_SERVICE);
    if (data != null) {
        mCurrentTemp = parseTemp(data);
    } else {
        mCurrentTemp = 0f;
    }
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:15,代码来源:TemperatureBeacon.java

示例8: parseScanRecordFromBytes

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
public static ScanRecord parseScanRecordFromBytes(byte[] bytes) {
    try {
        Method parseFromBytes = ScanRecord.class.getMethod("parseFromBytes", byte[].class);
        return (ScanRecord) parseFromBytes.invoke(null, (Object) bytes);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:hello,项目名称:android-buruberi,代码行数:9,代码来源:Testing.java

示例9: processResult

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例10: onScanResult

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例11: BLEScanner

import android.bluetooth.le.ScanRecord; //导入依赖的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

示例12: scanPeripheralWithServicesUUID_API21

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
public void scanPeripheralWithServicesUUID_API21(final String uuid) {
    	if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
    		requestOpenBT();
    		return;
    	}
    	BluetoothLeScanner scanner = mBluetoothAdapter.getBluetoothLeScanner();
    	ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
    	List<ScanFilter> list = new ArrayList<ScanFilter>(1);
    	
    	ScanCallback callback = new ScanCallback() {
			@Override
		    public void onScanResult(int callbackType,  android.bluetooth.le.ScanResult result) {
				BluetoothDevice device = result.getDevice();
				
				ScanRecord sr = result.getScanRecord();
			    
				int rssi = result.getRssi();
//				if (rssi > -15) {
//					runCallbackWithErrorCode(BLEUtilErrorCode.E_RSSI_ERROR);
//					return;
//				}
//				if (rssi < -35) {
//					runCallbackWithErrorCode(BLEUtilErrorCode.E_RSSI_TOO_LOW);
//					return;
//				}
				if (matchRules(rssi, sr.getBytes(), uuid)) {
					connectToDevice(device);
				}
		    }
		 
		    @Override
		    public void onScanFailed(int errorCode) {
		 
		    }
		};
    	
    	if (uuid != null) {
	    	ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(uuid)).build();
	        list.add(filter);
	        scanner.startScan(list, settings, callback);
    	} else {
//    		scanner.startScan(null, settings, callback);
    		scanner.startScan(callback);
    	}
    }
 
开发者ID:kingbeful,项目名称:BLECommunication,代码行数:46,代码来源:BLEUtil.java

示例13: initScanData

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
private void initScanData() {
        scanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                super.onScanResult(callbackType, result);
                Log.d(TAG, "["+
                        Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
                        Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
                        Thread.currentThread().getStackTrace()[2].getMethodName() + "]");
                Log.i(TAG, "result" + result);
                String address = result.getDevice().getAddress();
                String name;
                ScanRecord scanRecord = result.getScanRecord();
                int mRssi = result == null ? -127: result.getRssi();
                Log.i(TAG, "Rssi: " +mRssi);
                name = scanRecord == null ? "unknown" : scanRecord.getDeviceName();
                //TODO stop scan
//                if (name != null)
//                {
//                    Log.d(TAG, "["+
//                            Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
//                            Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
//                            Thread.currentThread().getStackTrace()[2].getMethodName() + "]" + "========StopScan");
//                    stopScan();
//                }

                scanResultListener.onResultReceived(name, address, mRssi);
            }

            @Override
            public void onBatchScanResults(List<ScanResult> results) {
                super.onBatchScanResults(results);
                Log.d(TAG, "["+
                        Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
                        Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
                        Thread.currentThread().getStackTrace()[2].getMethodName() + "]");
                Log.e(TAG, "onBatchScanResults");
            }

            @Override
            public void onScanFailed(int errorCode) {
                super.onScanFailed(errorCode);
                Log.d(TAG, "["+
                        Thread.currentThread().getStackTrace()[2].getFileName() + "_" +
                        Thread.currentThread().getStackTrace()[2].getLineNumber() + "_" +
                        Thread.currentThread().getStackTrace()[2].getMethodName() + "]");
                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:AnXi-TieGuanYin-Tea,项目名称:AndroidBluttoothMasterAndSlave,代码行数:55,代码来源:BLEScanner.java

示例14: handleScanResult

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
private void handleScanResult (  ScanResult scanResult) {

        BluetoothDevice aBluetoothDevice = scanResult.getDevice() ;

        Log.d (TAG, "handleScanResult aBluetoothDevice =" + aBluetoothDevice.toString()) ;

        foundBluetoothDevices.put(aBluetoothDevice.getAddress(), aBluetoothDevice) ;

        refreshView(foundBluetoothDevices);

        aBluetoothDevice.getName() ;
        aBluetoothDevice.getAddress() ;
        aBluetoothDevice.getBluetoothClass() ;

        ScanRecord aScanRecord =  scanResult.getScanRecord() ;
        int signalStrengthDbm =  scanResult.getRssi() ;
        // signal strength in dBm.
        //dBmW or Decibel-milliwatts),  power ratio in decibels (dB) of the measured power
        // referenced to one milliwatt (mW)

        scanResult.getTimestampNanos() ;


    }
 
开发者ID:smitzey,项目名称:wearbooksource,代码行数:25,代码来源:BleScanScanActivity.java

示例15: parseScanResult

import android.bluetooth.le.ScanRecord; //导入依赖的package包/类
protected void parseScanResult(ScanResult scanResult) {
    ScanRecord scanRecord = scanResult.getScanRecord();
    if (scanRecord == null) {
        return;
    }
    double rssi = scanResult.getRssi();
    byte[] bytes = scanRecord.getServiceData(EDDYSTONE_SPEC);
    updateRssi(rssi);
    FrameType type = frameTypeFromBytes(bytes);
    if (type != null) {
        switch (type) {
            case URL:
                UrlFrame urlFrame = UrlFrame.frameWithBytes(bytes);
                if (urlFrame != null) {
                    mFrames[0] = urlFrame;
                    Global.log("Parsed URL Frame with mUrl: " + urlFrame.mUrl);
                    notifyChange();
                }
                break;
            case UID:
                UidFrame uidFrame = UidFrame.frameWithBytes(bytes);
                if (uidFrame != null) {
                    mFrames[1] = uidFrame;
                    Global.log("Parsed UID Frame with uid: " + uidFrame.getUid());
                    notifyChange();
                }
                break;
            case TLM:
                TlmFrame tlmFrame = TlmFrame.frameWithBytes(bytes);
                if (tlmFrame != null) {
                    mFrames[2] = tlmFrame;
                    Global.log("Parsed TLM Frame with battery: " + tlmFrame.mBatteryVolts + " temperature: " + tlmFrame.mTemperature + " advertisement count: " + tlmFrame.mAdvertisementCount
                            + " on time: " + tlmFrame.mOnTime);
                    notifyChange();
                }
                break;
            default:
                break;
        }
    }
}
 
开发者ID:BlueBiteLLC,项目名称:eddystone-android,代码行数:42,代码来源:Beacon.java


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