当前位置:首页 » 安卓系统 » androidble配对

androidble配对

发布时间: 2022-08-02 17:49:16

Ⅰ 为什么安卓6.0需要开启定位才能搜索蓝牙ble设备

电脑蓝牙和手机蓝牙一般用来相互之间传文件。是无法查看对方的盘符里的文件的。
电脑发送文件给手机:
右击“我的蓝牙“图标,选发送文件。
找到想要发送的手机,然后点击该手机。
选择要传送的文件。
第一次连接,手机端需要按提示输入一个配对码。对方选择接收即可。
手机给电脑发送文件:
1.选择手机上的文件,点击“分享”,以蓝牙方式发送。
2.选择匹配的电脑即发送,等待电脑选择接收即可。

Ⅱ android蓝牙配对 如何自动配对设置PIN码

Android对于音频设备是自动输入0000的pin码的,参照$frameworks/base/core/java/android/server/BluetoothEventLoop.java 的onRequestPinCode()你若是在app里编写代码,可以在收到ACTION_PAIRING_REQUEST的时候,直接调用BluetoothDevice.setpin()reference $package/apps/Settings/src/android/settings/bluetooth/BluetoothPairingDialog.java 的onPair();

Ⅲ Android蓝牙BLE连接如何设置串口,数据格式为含1位起始位、7位数据位、1位奇偶校验位和1位终止位

字符长度=1+7+1+2=11 b/字符
数据速率R1=11×100=1100 b/s
有效数据速率R=7×100=700 b/s
选B

Ⅳ Android 蓝牙ble配对 发送PIN码无效问题

android蓝牙自动配对连接的具体代码如下:
1. 获取蓝牙适配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 为null,说明android手机没有蓝牙模块。
2. 判断蓝牙模块是否开启,blueadapter.isEnabled() true表示已经开启,false表示蓝牙并没启用。
3. 启动配置蓝牙可见模式,即进入可配对模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
4. 获取蓝牙适配器中已经配对的设备Set<BluetoothDevice> device=blueadapter.getBondedDevices();
当然,还需要在androidManifest.xml中声明蓝牙的权限
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5.自动配对设置Pin值
static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin)
throws Exception {
Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class });
Boolean result = (Boolean) autoBondMethod
.invoke(device, new Object[] { strPin.getBytes() });
return result;
}
6.开始配对请求
static public boolean createBond(Class btClass, BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}

Ⅳ Android BLE为什么首次连接蓝牙设备比较慢

光讲连接的话应该是不会出现这个问题的,你是不是做过保存连接的操作,所以第一次慢,以后快。

Ⅵ Android 手机可以通过 BLE 被扫描到吗

本文介绍Android ble 蓝牙4.0,也就是说API level >= 18,且支持蓝牙4.0的手机才可以使用,如果手机系统版本API
level < 18,也是用不了蓝牙4.0的哦。

首先发一下官方的demo,有兴趣的可以过去看看:http://developer.android.com/guide/topics/connectivity/bluetooth-le.html。android系统4.3以上,手机支持蓝牙4.0,具有搜索,配对,连接,发现服务及特征值,断开连接等功能,下载地址:http://download.csdn.net/detail/lqw770737185/8116019。

一、了解api及概念

1.1 BluetoothGatt

继承BluetoothProfile,通过BluetoothGatt可以连接设备(connect),发现服务(discoverServices),并把相应地属性返回到BluetoothGattCallback

1.2 BluetoothGattCharacteristic

相当于一个数据类型,它包括一个value和0~n个value的描述(BluetoothGattDescriptor)

1.3 BluetoothGattDescriptor

描述符,对Characteristic的描述,包括范围、计量单位等

1.4 BluetoothGattService

服务,Characteristic的集合。

1.5 BluetoothProfile

一个通用的规范,按照这个规范来收发数据。

1.6 BluetoothManager

通过BluetoothManager来获取BluetoothAdapter

BluetoothManager bluetoothManager = (BluetoothManager)
getSystemService(Context.BLUETOOTH_SERVICE);

1.7 BluetoothAdapter

一个Android系统只有一个BluetoothAdapter ,通过BluetoothManager 获取

BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();

1.8 BluetoothGattCallback

已经连接上设备,对设备的某些操作后返回的结果。这里必须提醒下,已经连接上设备后的才可以返回,没有返回的认真看看有没有连接上设备。

private BluetoothGattCallback GattCallback = new BluetoothGattCallback()
{

// 这里有9个要实现的方法,看情况要实现那些,用到那些就实现那些

public void onConnectionStateChange(BluetoothGatt gatt, int status, int
newState){};

public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status){};

};

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

BluetoothGatt gatt = device.connectGatt(this, false, mGattCallback);

1.8.1:notification对应onCharacteristicChanged;

gatt.setCharacteristicNotification(characteristic, true);

1.8.2:readCharacteristic对应onCharacteristicRead;

gatt.readCharacteristic(characteristic);

1.8.3: writeCharacteristic对应onCharacteristicWrite;

gatt.wirteCharacteristic(mCurrentcharacteristic);

1.8.4:连接蓝牙或者断开蓝牙 对应 onConnectionStateChange;

1.8.5: readDescriptor对应onDescriptorRead;

1.8.6:writeDescriptor对应onDescriptorWrite;

gatt.writeDescriptor(descriptor);

1.8.7:readRemoteRssi对应onReadRemoteRssi;

gatt.readRemoteRssi()

1.8.8:executeReliableWrite对应onReliableWriteCompleted;

1.8.9:discoverServices对应onServicesDiscovered。

gatt.discoverServices()

1.9 BluetoothDevice

扫描后发现可连接的设备,获取已经连接的设备

二、开启蓝牙权限如果
android.hardware.bluetooth_le设置为false,可以安装在不支持的设备上使用,判断是否支持蓝牙4.0用以下代码就可以了

if
(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
{

Toast.makeText(this, "设备不支持蓝牙4.0", Toast.LENGTH_SHORT).show();

finish();

}

三、对蓝牙的启动关闭操作

1、利用系统默认开启蓝牙对话框

if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {

Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

}

2、后台打开蓝牙,不做任何提示,这个也可以用来自定义打开蓝牙对话框啦

mBluetoothAdapter.enable();

3、后台关闭蓝牙

mBluetoothAdapter.disable();

四、扫描设备,连接设备,获取设备信息 ,断开连接设备,自行查看官方demo,还是看demo比较清晰啊

Ⅶ 安卓编程,蓝牙连接怎么做

Android 蓝牙编程的基本步骤:

  1. 获取蓝牙适配器BluetoothAdapterblueadapter=BluetoothAdapter.getDefaultAdapter();

    如果BluetoothAdapter 为null,说明android手机没有蓝牙模块。

  2. 判断蓝牙模块是否开启,blueadapter.isEnabled() true表示已经开启,false表示蓝牙并没启用。

  3. 启动配置蓝牙可见模式,即进入可配对模式Intentin=newIntent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

    in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,200);

    startActivity(in); ,200就表示200秒。

  4. 获取蓝牙适配器中已经配对的设备Set<BluetoothDevice>device=blueadapter.getBondedDevices();

当然,还需要在androidManifest.xml中声明蓝牙的权限

<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

接下来就是根据自己的需求对BluetoothAdapter的操作了。

Ⅷ android 蓝牙BLE 多设备连接

一次只能连接一个外围设备吧

热点内容
沪江网校安卓怎么倍速播放 发布:2024-05-16 23:19:25 浏览:398
支付宝怎么设置登陆密码怎么设置密码 发布:2024-05-16 23:18:07 浏览:834
为什么修改wifi密码后无法加入 发布:2024-05-16 23:03:04 浏览:737
车机安卓未知来源在设置哪里 发布:2024-05-16 22:31:48 浏览:795
红包邀请验证码在哪里填安卓手机 发布:2024-05-16 22:30:01 浏览:643
上传日上限 发布:2024-05-16 22:26:08 浏览:859
c语言基本概念 发布:2024-05-16 21:44:16 浏览:190
sqlserver跨库查询 发布:2024-05-16 21:36:56 浏览:164
sql多表连接语句 发布:2024-05-16 21:21:53 浏览:301
sqlscope 发布:2024-05-16 21:17:37 浏览:966