本文整理匯總了Java中android.bluetooth.le.ScanResult類的典型用法代碼示例。如果您正苦於以下問題:Java ScanResult類的具體用法?Java ScanResult怎麽用?Java ScanResult使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ScanResult類屬於android.bluetooth.le包,在下文中一共展示了ScanResult類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// initialize the right scan callback for the current API level
if (Build.VERSION.SDK_INT >= 21) {
mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
mRecyclerViewAdapter.addDevice(result.getDevice().getAddress());
}
};
} else {
mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) {
mRecyclerViewAdapter.addDevice(bluetoothDevice.getAddress());
}
};
}
// initialize bluetooth manager & adapter
BluetoothManager manager = (BluetoothManager) getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = manager.getAdapter();
}
示例2: onBatchScanResults
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
public void onBatchScanResults(List<ScanResult> results) {
CallsCounter.logCounter(context, "BluetoothLEScanCallback21.onBatchScanResults", "BluetoothLEScanCallback21.onBatchScanResults");
boolean scanStarted = (BluetoothScanJob.getWaitForLEResults(context));
if (scanStarted) {
for (ScanResult result : results) {
//PPApplication.logE("BluetoothLEScanCallback21", "onBatchScanResults - result=" + result.toString());
BluetoothDevice device = result.getDevice();
String btName = device.getName();
PPApplication.logE("BluetoothLEScanCallback21", "onBatchScanResults - deviceName=" + btName);
BluetoothDeviceData deviceData = new BluetoothDeviceData(btName, device.getAddress(),
BluetoothScanJob.getBluetoothType(device), false, 0);
BluetoothScanJob.addLEScanResult(deviceData);
}
}
}
示例3: 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;
}
}
}
}
}
示例4: stopScan
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
/**
* Stops scanning for devices
*
* @return An Observable which emits ScanResult
*/
public Observable<ScanResult> stopScan() {
return Observable.create(subscriber -> {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
if (scanner != null) {
scanner.stopScan(getScanCallback(subscriber));
} else {
Log.e(TAG, "BluetoothLeScanner is null");
subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
}
} else {
Log.e(TAG, "BluetoothAdapter is null");
subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
}
});
}
示例5: onScanResult
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
BluetoothDevice device = result.getDevice();
if ( device != null )
{
String msg = device.getName() + "\n" +"[RSSI : " + result.getRssi() + "dBm]" + device.getAddress();
NLog.d( "onLeScan " + msg );
/**
* setting pen client control for ble
*/
if(!temp.contains( device.getAddress() ))
{
NLog.d( "ACTION_FOUND onLeScan : " +device.getName() + " address : "+ device.getAddress()+", COD:" + device.getBluetoothClass());
temp.add( device.getAddress());
mNewDevicesArrayAdapter.add(msg);
}
}
}
示例6: BluetoothLeScanL21Proxy
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public BluetoothLeScanL21Proxy(BluetoothAdapter bluetoothAdapter) {
mBluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
mLeScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
};
}
示例7: onEvent
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
public void onEvent(@NonNull PlenScanService.StateTransitionEvent event) {
mView.ifPresent(fragment -> {
switch (event.getNewState()) {
case SCANNING:
fragment.notifyPlenScanning();
break;
case STOP:
if (!mScanResults.isPresent()) {
fragment.notifyPlenScanCancel();
} else {
List<String> addresses = Observable.from(mScanResults.get())
.map(ScanResult::getDevice)
.map(BluetoothDevice::getAddress)
.distinct().toList().toBlocking().single();
fragment.notifyPlenScanComplete(addresses);
}
break;
}
});
}
開發者ID:plenprojectcompany,項目名稱:plen-Scenography_Android,代碼行數:21,代碼來源:PlenConnectionActivityPresenter.java
示例8: onScanResult
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Override
public void onScanResult(final int callbackType, final ScanResult result) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.i(bleManager.LOG_TAG, "DiscoverPeripheral: " + result.getDevice().getName());
String address = result.getDevice().getAddress();
Peripheral peripheral = null;
if (!bleManager.peripherals.containsKey(address)) {
peripheral = new Peripheral(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes(), reactContext);
bleManager.peripherals.put(address, peripheral);
} else {
peripheral = bleManager.peripherals.get(address);
peripheral.updateRssi(result.getRssi());
peripheral.updateData(result.getScanRecord().getBytes());
}
WritableMap map = peripheral.asWritableMap();
bleManager.sendEvent("BleManagerDiscoverPeripheral", map);
}
});
}
示例9: getView
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ScanResult scanResult = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext())
.inflate(R.layout.list_item_scanresult, parent, false);
}
TextView name = (TextView)convertView.findViewById(R.id.scan_result_name);
name.setText(scanResult.getDevice().getName());
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mScanPresenter.onClickConnect(getItem(position));
}
});
return convertView;
}
示例10: testScanForBleDevices
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Test
public void testScanForBleDevices() {
ScanResult savedResult = mock(ScanResult.class);
Map<String, ScanResult> resultMap = new HashMap<>();
resultMap.put("EB:22:19:0E:B2:01", savedResult);
mScanner.mAddressToScanResult = resultMap;
mScanner.scanForBleDevices();
verify(mHandler, times(1)).removeCallbacks(mScanner.mStopScanAction);
verify(mAndroidScanner, times(1)).stopScan(mScanner.mScanCallback);
assertTrue(resultMap.size() == 0); // make sure saved result was cleared
verify(mAndroidScanner, times(1)).startScan(mScanner.mScanCallback);
verify(mHandler, times(1))
.postDelayed(mScanner.mStopScanAction, BleScanner.BLE_SCAN_DURATION_MS);
}
示例11: testGetListItemView
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Test
public void testGetListItemView() {
activity.mScanPresenter = presenter;
ScanResult result = mock(ScanResult.class);
BluetoothDevice device = mock(BluetoothDevice.class);
doReturn(device).when(result).getDevice();
doReturn("testName").when(device).getName();
activity.mAdapter.add(result);
View view = activity.mAdapter.getView(0, null, null);
view.callOnClick();
verify(presenter, times(1)).onClickConnect(result);
TextView name = (TextView)view.findViewById(R.id.scan_result_name);
assertEquals("testName", name.getText());
}
示例12: onScanResult
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
if (devices != null) {
BluetoothDevice device = result.getDevice();
/*
if ((device.getName() != null) && !devices.containsKey(device.getAddress())) {
debug("New device detected " + device.getAddress() + " " + device.getName());
if (device.getName().toUpperCase().contains("U2F")) {
devices.put(device.getAddress(), device);
}
}
*/
if (!devices.containsKey(device.getAddress())) {
debug("New device detected " + device.getAddress() + "/" + (device.getName() != null ? device.getName() : ""));
devices.put(device.getAddress(), device);
}
}
}
示例13: onScan
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
/**
* callback from BLECentral
*
* @param callbackType
* @param scanResult
*/
@Override
public void onScan(int callbackType, ScanResult scanResult) {
if (connectedDevices.containsKey(scanResult.getDevice().getAddress())) {
// If we're already connected, forget it
//Timber.d("Denied connection. Already connected to " + scanResult.getDevice().getAddress());
return;
}
if (centralScannedDevices.contains(scanResult.getDevice().getAddress())) {
// If we're already connected, forget it
//Timber.d("Denied connection. Already connecting to " + scanResult.getDevice().getAddress());
return;
}
centralScannedDevices.add(scanResult.getDevice().getAddress());
Timber.d("GATT Initiating connection to " + scanResult.getDevice().getAddress());
scanResult.getDevice().connectGatt(context, false, getGattCallback());
}
示例14: 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);
}
示例15: startScan
import android.bluetooth.le.ScanResult; //導入依賴的package包/類
/**
* Starts scanning for devices
*
* @return An Observable which emits ScanResult
*/
public Observable<ScanResult> startScan() {
return Observable.create(subscriber -> {
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
if (scanner != null) {
scanner.startScan(getScanCallback(subscriber));
} else {
Log.e(TAG, "BluetoothLeScanner is null");
subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
}
} else {
Log.e(TAG, "BluetoothAdapter is null");
subscriber.onError(new NullPointerException("BluetoothLeScanner is null"));
}
});
}