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


Java ScanCallback类代码示例

本文整理汇总了Java中android.bluetooth.le.ScanCallback的典型用法代码示例。如果您正苦于以下问题:Java ScanCallback类的具体用法?Java ScanCallback怎么用?Java ScanCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScanCallback类属于android.bluetooth.le包,在下文中一共展示了ScanCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.bluetooth.le.ScanCallback; //导入依赖的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: errorCodeToBleErrorCode

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
@BleScanException.Reason private static int errorCodeToBleErrorCode(int errorCode) {
    switch (errorCode) {
        case ScanCallback.SCAN_FAILED_ALREADY_STARTED:
            return BleScanException.SCAN_FAILED_ALREADY_STARTED;
        case ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
            return BleScanException.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED;
        case ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED:
            return BleScanException.SCAN_FAILED_FEATURE_UNSUPPORTED;
        case ScanCallback.SCAN_FAILED_INTERNAL_ERROR:
            return BleScanException.SCAN_FAILED_INTERNAL_ERROR;
        case 5: // ScanCallback.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES
            return BleScanException.SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES;
        default:
            RxBleLog.w("Encountered unknown scanning error code: %d -> check android.bluetooth.le.ScanCallback");
            return BleScanException.UNKNOWN_ERROR_CODE;
    }
}
 
开发者ID:Polidea,项目名称:RxAndroidBle,代码行数:18,代码来源:ScanOperationApi21.java

示例3: startDiscoveringBle

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
private boolean startDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ startDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "startDiscoveringBle() : Already in classic discovering mode");
		return true;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "startDiscoveringBle() : Choose startScan()");
		mLeScanner = mAdapter.getBluetoothLeScanner();
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).startScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.startScan(mScanCallback); ???
	} else {
		Log.i(TAG, "startDiscoveringBle() : Choose startLeScan()");
		return mAdapter.startLeScan(mLeScanCallback);
	}
	return true;
}
 
开发者ID:BohanLu,项目名称:NobleAries,代码行数:27,代码来源:Chores.java

示例4: onListItemClick

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressWarnings("deprecation")
protected void onListItemClick(ListView l, View v, int position, long id) {
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null) return;
    final Intent intent = new Intent(this, DeviceControlActivity.class);
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName());
    intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
    if (mScanning) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBluetoothLeScanner.stopScan(new ScanCallback() {});
        } else {
            mBluetoothAdapter.stopLeScan(mLeScanCallback);
        }
        mScanning = false;
    }
    startActivity(intent);
}
 
开发者ID:igrow-systems,项目名称:igrow-android,代码行数:20,代码来源:DeviceScanActivity.java

示例5: BluetoothLeScanL21Proxy

import android.bluetooth.le.ScanCallback; //导入依赖的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

示例6: cancelDiscoveringBle

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
private boolean cancelDiscoveringBle(){
	
	if (D) Log.d(TAG, "+++ cancelDiscoveringBle() +++");
	
	if (mAdapter.isDiscovering()){
		Log.i(TAG, "cancelDiscoveringBle() : In classic discovering mode");
		return false;
	}
	
	if (isLollipopApi){
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopScan()");
		
		if (null != mLeScanner){
			((BluetoothLeScanner)mLeScanner).stopScan((ScanCallback)mScanCallback);
			return true;
		}
		
		// TODO
		// return mAdapter.stopScan(mScanCallback); ???
	} else {
		Log.i(TAG, "cancelDiscoveringBle() : Choose stopLeScan()");
		mAdapter.stopLeScan(mLeScanCallback);
	}
	return true;
}
 
开发者ID:BohanLu,项目名称:NobleAries,代码行数:26,代码来源:Chores.java

示例7: scanFailureToString

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
/**
 * Returns the corresponding constant name for a
 * given {@code ScanCallback#SCAN_FAILED_*} value.
 */
public static String scanFailureToString(int scanFailure) {
    switch (scanFailure) {
        case ScanCallback.SCAN_FAILED_ALREADY_STARTED:
            return "SCAN_FAILED_ALREADY_STARTED";

        case ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED:
            return "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED";

        case ScanCallback.SCAN_FAILED_INTERNAL_ERROR:
            return "SCAN_FAILED_INTERNAL_ERROR";

        case ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED:
            return "SCAN_FAILED_FEATURE_UNSUPPORTED";

        default:
            return "UNKNOWN: " + scanFailure;
    }
}
 
开发者ID:hello,项目名称:android-buruberi,代码行数:23,代码来源:LowEnergyScanException.java

示例8: startScan

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
public static void startScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.startScan(callback);
}
 
开发者ID:pangliang,项目名称:miband-sdk-android,代码行数:14,代码来源:MiBand.java

示例9: stopScan

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
public static void stopScan(ScanCallback callback) {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (null == adapter) {
        Log.e(TAG, "BluetoothAdapter is null");
        return;
    }
    BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
    if (null == scanner) {
        Log.e(TAG, "BluetoothLeScanner is null");
        return;
    }
    scanner.stopScan(callback);
}
 
开发者ID:pangliang,项目名称:miband-sdk-android,代码行数:14,代码来源:MiBand.java

示例10: BTLEScannerOld

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
public BTLEScannerOld(BluetoothAdapter bluetoothAdapter, Callback callback) {
    this.bluetoothAdapter = bluetoothAdapter;
    this.leScanCallback = callback::onScan;

    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        this.leScanner = bluetoothAdapter.getBluetoothLeScanner();

        this.scanCallback = new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
                    callback.onScan(result.getDevice(), result.getRssi(), result.getScanRecord().getBytes());
                }

                super.onScanResult(callbackType, result);
            }
        };
    } else {
        this.leScanner = null;
        this.scanCallback = null;
    }
}
 
开发者ID:devicehive,项目名称:android-ble,代码行数:23,代码来源:BTLEScannerOld.java

示例11: startScan

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
public void startScan() {
    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        leScanner.startScan(new android.bluetooth.le.ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {

                super.onScanResult(callbackType, result);
            }

            @Override
            public void onBatchScanResults(List<ScanResult> results) {
                super.onBatchScanResults(results);
            }
        });
    } else {
        bluetoothAdapter.startLeScan(leScanCallback);
    }
}
 
开发者ID:devicehive,项目名称:android-ble,代码行数:19,代码来源:BTLEScannerOld.java

示例12: getScanCallback

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
@NonNull
private ScanCallback getScanCallback(final byte[] serviceData) {
    return new ScanCallback() {
            @Override
            public void onScanResult(int callbackType, ScanResult result) {
                processResult(result);
            }

            @Override
            public void onBatchScanResults(List<ScanResult> results) {
                for (ScanResult s: results) {
                    processResult(s);
                }
            }

            @Override
            public void onScanFailed(int errorCode) {
                Log.d(TAG, "Scan failed: " + String.valueOf(errorCode));
            }

            public void processResult(ScanResult sr) {
                Log.d(TAG, "Found device " + sr.getDevice().getName() + "(" + sr.getDevice().getAddress() + ")");

                /* confirm correct connection key */
                byte[] sd = sr.getScanRecord().getServiceData(Constants.SERVICE_pUUID);
                if (sd != null) {
                    if (Arrays.equals(sd, serviceData)) {
                        BTConnection.this.stopScan();
                        transfer.startServer(sr.getDevice());
                    } else {
                        Log.d(TAG, "Incorrect service data: " + new String(sd) + " instead of " + new String(serviceData) + ". Continuing.");
                    }
                } else {
                    Log.d(TAG, "No service data received -- continuing.");
                }
            }
        };
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:39,代码来源:BTConnection.java

示例13: initCallbacks

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
private ScanCallback initCallbacks() {
    return new ScanCallback() {
        @Override
        public void onScanResult(int callbackType, ScanResult result) {
            super.onScanResult(callbackType, result);

            if (result != null && result.getDevice() != null) {
                if (isAdded(result.getDevice())) {
                    // No add
                } else {
                    saveDevice(result.getDevice());
                }
            }

        }

        @Override
        public void onBatchScanResults(List<ScanResult> results) {
            super.onBatchScanResults(results);
        }

        @Override
        public void onScanFailed(int errorCode) {
            super.onScanFailed(errorCode);
        }
    };
}
 
开发者ID:jphacks,项目名称:KB_1711,代码行数:28,代码来源:MainActivity.java

示例14: bleStopScan

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
/**
 * Stop a BLE scan.
 *
 * @param callbackId The callbackId corresponding to the {@link
 *     BluetoothLeScannerSnippet#bleStartScan} call that started the scan.
 * @throws BluetoothLeScanSnippetException
 */
@RpcMinSdk(Build.VERSION_CODES.LOLLIPOP_MR1)
@Rpc(description = "Stop a BLE scan.")
public void bleStopScan(String callbackId) throws BluetoothLeScanSnippetException {
    ScanCallback callback = mScanCallbacks.remove(callbackId);
    if (callback == null) {
        throw new BluetoothLeScanSnippetException("No ongoing scan with ID: " + callbackId);
    }
    mScanner.stopScan(callback);
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:17,代码来源:BluetoothLeScannerSnippet.java

示例15: shutdown

import android.bluetooth.le.ScanCallback; //导入依赖的package包/类
@Override
public void shutdown() {
    for (ScanCallback callback : mScanCallbacks.values()) {
        mScanner.stopScan(callback);
    }
    mScanCallbacks.clear();
}
 
开发者ID:google,项目名称:mobly-bundled-snippets,代码行数:8,代码来源:BluetoothLeScannerSnippet.java


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