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


Java ScanResult类代码示例

本文整理汇总了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();
}
 
开发者ID:martindisch,项目名称:SensorTag-Accelerometer,代码行数:27,代码来源:ScanFragment.java

示例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);
        }
    }
}
 
开发者ID:henrichg,项目名称:PhoneProfilesPlus,代码行数:21,代码来源:BluetoothLEScanCallback21.java

示例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;
        }
      }
    }
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:21,代码来源:NewDevicePresenter.java

示例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"));
        }
    });
}
 
开发者ID:dkhmelenko,项目名称:miband-android,代码行数:23,代码来源:MiBand.java

示例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);
            }
    }
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:21,代码来源:DeviceListActivity.java

示例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);
        }
    };
}
 
开发者ID:igrow-systems,项目名称:igrow-android,代码行数:24,代码来源:BluetoothLeScanL21Proxy.java

示例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);
		}
	});
}
 
开发者ID:innoveit,项目名称:react-native-ble-manager,代码行数:25,代码来源:LollipopScanManager.java

示例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;
}
 
开发者ID:alexamster,项目名称:ProjectPlutoAndroid,代码行数:20,代码来源:ScanActivity.java

示例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);
}
 
开发者ID:alexamster,项目名称:ProjectPlutoAndroid,代码行数:18,代码来源:BleScannerTest.java

示例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());

}
 
开发者ID:alexamster,项目名称:ProjectPlutoAndroid,代码行数:17,代码来源:ScanActivityTest.java

示例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);
		}				
	}
}
 
开发者ID:LedgerHQ,项目名称:u2f-ble-test,代码行数:20,代码来源:MainActivity.java

示例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());
}
 
开发者ID:wl1244hotmai,项目名称:BLE-Mesh,代码行数:25,代码来源:BLEGattClients.java

示例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);
}
 
开发者ID:Jasonchenlijian,项目名称:FastBle,代码行数:15,代码来源:BleManager.java

示例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"));
        }
    });
}
 
开发者ID:dkhmelenko,项目名称:miband-android,代码行数:23,代码来源:MiBand.java


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