本文整理汇总了Java中android.bluetooth.BluetoothAdapter.LeScanCallback方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.LeScanCallback方法的具体用法?Java BluetoothAdapter.LeScanCallback怎么用?Java BluetoothAdapter.LeScanCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.LeScanCallback方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.bluetooth.BluetoothAdapter; //导入方法依赖的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: stopScan
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* 停止扫描蓝牙设备
*
* @param callback
*/
public void stopScan(BluetoothAdapter.LeScanCallback callback) {
bluetoothAdapter.stopLeScan(callback);
if (connectionState == STATE_SCANNING) {
connectionState = STATE_DISCONNECTED;
}
}
示例3: stopScan
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* 停止搜索
* @param callback
*/
public void stopScan(BluetoothAdapter.LeScanCallback callback) {
if (callback instanceof PeriodScanCallback) {
((PeriodScanCallback) callback).removeHandlerMsg();
}
bluetoothAdapter.stopLeScan(callback);
if (connectionState == STATE_SCANNING) {
connectionState = STATE_DISCONNECTED;
}
}
示例4: getOldScanCallback
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private BluetoothAdapter.LeScanCallback getOldScanCallback() {
return this;
}
示例5: startLeScan
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Starts a scan for Bluetooth LE devices.
* <p/>
* <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @param callback the callback LE scan results are delivered (这个回调对扫描结果进行传递)
* @return true, if the scan was started successfully
*/
public boolean startLeScan(BluetoothAdapter.LeScanCallback callback) {
boolean suc = bluetoothAdapter.startLeScan(callback);
if (suc) {
connectionState = STATE_SCANNING;
}
return suc;
}