在Android 8.0(API第26级)和更高版本的设备上,您可以在试图通过蓝牙、BLE和wi - fi对其他设备进行配对时定制配对请求对话框
2018-01-04 11:34
2071 查看
在运行Android 8.0(API第26级)和更高版本的设备上,您可以在试图通过蓝牙、BLE和wi - fi对其他设备进行配对时定制配对请求对话框。<
4000
/span>在您的应用程序中,您可以指定用户是否看到了可能的伙伴设备列表,或者只是对一个配套设备的一个建议。您还可以过滤在配对请求对话框中出现的条目,比如type(蓝牙、BLE和wi - fi)或设备名称。
4000
/span>在您的应用程序中,您可以指定用户是否看到了可能的伙伴设备列表,或者只是对一个配套设备的一个建议。您还可以过滤在配对请求对话框中出现的条目,比如type(蓝牙、BLE和wi - fi)或设备名称。
public class MyDeviceSelectionActivity { private CompanionDeviceManager mDeviceManager; private AssociationRequest mPairingRequest; private BluetoothDeviceFilter mDeviceFilter; private static final int SELECT_DEVICE_REQUEST_CODE = 42; @override public void onCreate() { // ... mDeviceManager = getSystemService(CompanionDeviceManager.class); // To skip filtering based on name and supported feature flags (UUIDs), // don't include calls to setNamePattern() and addServiceUuid(), // respectively. This example uses Bluetooth. mDeviceFilter = new BluetoothDeviceFilter.Builder() .setNamePattern(Pattern.compile("My device")) .addServiceUuid(new ParcelUuid(new UUID(0x123abcL, -1L))) .build(); // The argument provided in setSingleDevice() determines whether a single // device name or a list of device names is presented to the user as // pairing options. mPairingRequest = new AssociationRequest.Builder() .addDeviceFilter(mDeviceFilter) .setSingleDevice(true) .build(); // When the app tries to pair with the Bluetooth device, show the // appropriate pairing request dialog to the user. mDeviceManager.associate(mPairingRequest, new CompanionDeviceManager.Callback() { @Override public void onDeviceFound(IntentSender chooserLauncher) { startIntentSenderForResult(chooserLauncher, SELECT_DEVICE_REQUEST_CODE, null, 0, 0, 0); } }, null); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SELECT_DEVICE_REQUEST_CODE && resultCode == Activity.RESULT_OK) { // User has chosen to pair with the Bluetooth device. BluetoothDevice deviceToPair = data.getParcelableExtra(CompanionDeviceManager.EXTRA_DEVICE); deviceToPair.createBond(); // ... Continue interacting with the paired device. } } }
相关文章推荐
- wi - fi感知 运行Android 8.0(API级别26)和更高的设备上
- android蓝牙--不支持ble设备的旧api
- VC++编程通过Bluetooth API调用对话框选择蓝牙设备并显示设备信息
- 【分享】 使用MacBook Pro共享网络让其他PC和手持设备通过wi-fi上网方法
- VC++编程通过Bluetooth API调用对话框选择蓝牙设备并显示设备信息
- WINCE蓝牙如何检测被其他设备发起配对请求
- Android BLE最完整的工具类(扫描/连接/读写/通知设备),可以手机与设备进行通讯
- android蓝牙--不支持ble设备的旧api
- HNS物联网僵尸网络现在通过Wi-Fi使用ADB传播到新的Android设备
- 通过局域网对连接的Android设备进行调试
- Android开发之蓝牙连接与配对设备
- restful接口就是url嘛,通过http请求发起访问。那接口进行监控,就可以监控这个restful url嘛
- Android官网培训课:用Wi-Fi Direct进行网络连接
- 使用passthrough模式,只通过PCI任意设备(该过程是在RHEL7系统进行,其他系统原理一样)
- 查看当前android设备api版本
- win7与android设备通过蓝牙串口的连接方法
- Android SDK Manager无法下载其他版本的API 解决办法
- 自制智能插线板,内嵌BLE低功耗蓝牙,通过手机进行控制(一)
- 对Android设备通过局域网ADB进行调试