本文整理汇总了Java中android.bluetooth.le.ScanRecord.getServiceData方法的典型用法代码示例。如果您正苦于以下问题:Java ScanRecord.getServiceData方法的具体用法?Java ScanRecord.getServiceData怎么用?Java ScanRecord.getServiceData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.le.ScanRecord
的用法示例。
在下文中一共展示了ScanRecord.getServiceData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
});
}
示例3: 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();
}
示例4: 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;
}
}
示例5: 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.");
}
}
示例6: 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;
}
}
};
}
示例7: 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;
}
}
}