本文整理匯總了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;
}