请问单片机中如何设置android 蓝牙 uuid的UUID?谢谢!

对于蓝牙UUID,跪求高手解释_android吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:571,142贴子:
对于蓝牙UUID,跪求高手解释收藏
请大婶解释解释下,UUID是什么?怎么获取? 如果B 手机去跟A手机蓝牙连接,那UUID是用A的还是用B的??彻底迷糊了。
现在小学三年级的暑假作业真难啊!昨天看到侄子的暑假作业有一题什么逻辑规律题,哥想了半天都想不出来,求各位大神解答:986F、875E、764D、653C、___、431A,请问___处应该填什么?求解啊~~~
我勒个去, 542B
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或BLE4.0蓝牙概述_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
喜欢此文档的还喜欢
BLE4.0蓝牙概述
B​L​E.蓝​牙​概​述
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢Android BlueTooth开发,如何获取其他设备的UUID?
根据Android APIs 中的说明,BluetoothService 和 BluetoothSocket的连接需要共享一个UUID,如果服务端和客户端都是自己开发,这个很容易实现。但是,我只在手机端开发一个客户端,如何与其他设备的蓝牙共享一个UUID呢?iOS 问题:我讲蓝牙外设的UUID归档和解档成功了,- (void)encodeWithCoder:(NSCoder *)aC
NSLog(@"归档执行");
[aCoder encodeObject:[NSString stringWithFormat:@"%@",_Peripheral] forKey:@"currentPeripheral"];
[aCoder encodeObject:self.UUID forKey:@"UUID"];
- (id)initWithCoder:(NSCoder *)aD
NSLog(@"解档执行");
self=[super init];
if (self) {
self.Peripheral=[aDecoder decodeObjectForKey:@"currentPeripheral"];
self.UUID = [aDecoder decodeObjectForKey:@"UUID"];
}但当我这样连接的时候 [file connectPeripherals:stores.UUID];
11:33:25.922 BLE-Communication[802:60b] -[__NSCFString setDelegate:]: unrecognized selector sent to instance 0x16ef90d0
11:33:25.925 BLE-Communication[802:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setDelegate:]: unrecognized selector sent to instance 0x16ef90d0' 会出现这样的错误,这是为什么? -
我讲蓝牙外设的UUID归档和解档成功了,- (void)encodeWithCoder:(NSCoder *)aC
NSLog(@"归档执行");
[aCoder encodeObject:[NSString stringWithFormat:@"%@",_Peripheral] forKey:@"currentPeripheral"];
[aCoder encodeObject:self.UUID forKey:@"UUID"];
- (id)initWithCoder:(NSCoder *)aD
NSLog(@"解档执行");
self=[super init];
if (self) {
self.Peripheral=[aDecoder decodeObjectForKey:@"currentPeripheral"];
self.UUID = [aDecoder decodeObjectForKey:@"UUID"];
}但当我这样连接的时候 [file connectPeripherals:stores.UUID];
11:33:25.922 BLE-Communication[802:60b] -[__NSCFString setDelegate:]: unrecognized selector sent to instance 0x16ef90d0
11:33:25.925 BLE-Communication[802:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setDelegate:]: unrecognized selector sent to instance 0x16ef90d0' 会出现这样的错误,这是为什么?
共有 2 个回答
看错误提示
NSCFString没有setDelegate方法
登录后方可回复
@M先森 : 那应该怎么弄啊?就是解档的时候???
登录后方可回复
登录后方可回答
耗时 0.0616 秒android蓝牙主动发起配对实例 - wiley - ITeye技术网站
博客分类:
package cn.madfinger.
import java.io.IOE
import java.lang.reflect.M
import java.util.ArrayL
import java.util.L
import java.util.UUID;
import android.app.A
import android.bluetooth.BluetoothA
import android.bluetooth.BluetoothD
import android.bluetooth.BluetoothS
import android.content.BroadcastR
import android.content.C
import android.content.I
import android.content.IntentF
import android.os.B
import android.util.L
import android.view.V
import android.widget.AdapterV
import android.widget.ArrayA
import android.widget.B
import android.widget.ListV
import android.widget.T
import android.widget.ToggleB
public class BlueToothTestActivity extends Activity {
//该UUID表示串口服务
//请参考文章
static final String SPP_UUID = "0-805F9B34FB";
Button btnSearch, btnDis, btnE
ToggleButton tbtnS
ListView lvBTD
ArrayAdapter&String& adtD
List&String& lstDevices = new ArrayList&String&();
BluetoothAdapter btA
public static BluetoothSocket btS
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Button 设置
btnSearch = (Button) this.findViewById(R.id.btnSearch);
btnSearch.setOnClickListener(new ClickEvent());
btnExit = (Button) this.findViewById(R.id.btnExit);
btnExit.setOnClickListener(new ClickEvent());
btnDis = (Button) this.findViewById(R.id.btnDis);
btnDis.setOnClickListener(new ClickEvent());
// ToogleButton设置
tbtnSwitch = (ToggleButton) this.findViewById(R.id.tbtnSwitch);
tbtnSwitch.setOnClickListener(new ClickEvent());
// ListView及其数据源 适配器
lvBTDevices = (ListView) this.findViewById(R.id.lvDevices);
adtDevices = new ArrayAdapter&String&(this,
android.R.layout.simple_list_item_1, lstDevices);
lvBTDevices.setAdapter(adtDevices);
lvBTDevices.setOnItemClickListener(new ItemClickEvent());
btAdapt = BluetoothAdapter.getDefaultAdapter();// 初始化本机蓝牙功能
// ========================================================
// modified by wiley
* if (btAdapt.getState() == BluetoothAdapter.STATE_OFF)// 读取蓝牙状态并显示
* tbtnSwitch.setChecked(false); else if (btAdapt.getState() ==
* BluetoothAdapter.STATE_ON) tbtnSwitch.setChecked(true);
if (btAdapt.isEnabled()) {
tbtnSwitch.setChecked(false);
tbtnSwitch.setChecked(true);
// ============================================================
// 注册Receiver来获取蓝牙设备相关的结果
IntentFilter intent = new IntentFilter();
intent.addAction(BluetoothDevice.ACTION_FOUND);// 用BroadcastReceiver来取得搜索结果
intent.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
intent.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
intent.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(searchDevices, intent);
private BroadcastReceiver searchDevices = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Bundle b = intent.getExtras();
Object[] lstName = b.keySet().toArray();
// 显示所有收到的消息及其细节
for (int i = 0; i & lstName. i++) {
String keyName = lstName[i].toString();
Log.e(keyName, String.valueOf(b.get(keyName)));
BluetoothDevice device =
// 搜索设备时,取得设备的MAC地址
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
device = intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (device.getBondState() == BluetoothDevice.BOND_NONE) {
String str = "未配对|" + device.getName() + "|"
+ device.getAddress();
if (lstDevices.indexOf(str) == -1)// 防止重复添加
lstDevices.add(str); // 获取设备名称和mac地址
adtDevices.notifyDataSetChanged();
}else if(BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
switch (device.getBondState()) {
case BluetoothDevice.BOND_BONDING:
Log.d("BlueToothTestActivity", "正在配对......");
case BluetoothDevice.BOND_BONDED:
Log.d("BlueToothTestActivity", "完成配对");
connect(device);//连接设备
case BluetoothDevice.BOND_NONE:
Log.d("BlueToothTestActivity", "取消配对");
protected void onDestroy() {
this.unregisterReceiver(searchDevices);
super.onDestroy();
android.os.Process.killProcess(android.os.Process.myPid());
class ItemClickEvent implements AdapterView.OnItemClickListener {
public void onItemClick(AdapterView&?& arg0, View arg1, int arg2,
long arg3) {
if(btAdapt.isDiscovering())btAdapt.cancelDiscovery();
String str = lstDevices.get(arg2);
String[] values = str.split("\\|");
String address = values[2];
Log.e("address", values[2]);
BluetoothDevice btDev = btAdapt.getRemoteDevice(address);
Boolean returnValue =
if (btDev.getBondState() == BluetoothDevice.BOND_NONE) {
//利用反射方法调用BluetoothDevice.createBond(BluetoothDevice remoteDevice);
Method createBondMethod = BluetoothDevice.class
.getMethod("createBond");
Log.d("BlueToothTestActivity", "开始配对");
returnValue = (Boolean) createBondMethod.invoke(btDev);
}else if(btDev.getBondState() == BluetoothDevice.BOND_BONDED){
connect(btDev);
} catch (Exception e) {
e.printStackTrace();
private void connect(BluetoothDevice btDev) {
UUID uuid = UUID.fromString(SPP_UUID);
btSocket = btDev.createRfcommSocketToServiceRecord(uuid);
Log.d("BlueToothTestActivity", "开始连接...");
btSocket.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
class ClickEvent implements View.OnClickListener {
public void onClick(View v) {
if (v == btnSearch)// 搜索蓝牙设备,在BroadcastReceiver显示结果
if (btAdapt.getState() == BluetoothAdapter.STATE_OFF) {// 如果蓝牙还没开启
Toast.makeText(BlueToothTestActivity.this, "请先打开蓝牙", 1000)
if (btAdapt.isDiscovering())
btAdapt.cancelDiscovery();
lstDevices.clear();
Object[] lstDevice = btAdapt.getBondedDevices().toArray();
for (int i = 0; i & lstDevice. i++) {
BluetoothDevice device = (BluetoothDevice) lstDevice[i];
String str = "已配对|" + device.getName() + "|"
+ device.getAddress();
lstDevices.add(str); // 获取设备名称和mac地址
adtDevices.notifyDataSetChanged();
setTitle("本机蓝牙地址:" + btAdapt.getAddress());
btAdapt.startDiscovery();
} else if (v == tbtnSwitch) {// 本机蓝牙启动/关闭
if (tbtnSwitch.isChecked() == false)
btAdapt.enable();
else if (tbtnSwitch.isChecked() == true)
btAdapt.disable();
} else if (v == btnDis)// 本机可以被搜索
Intent discoverableIntent = new Intent(
BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(
BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
} else if (v == btnExit) {
if (btSocket != null)
btSocket.close();
} catch (IOException e) {
e.printStackTrace();
BlueToothTestActivity.this.finish();
浏览 13926
浏览: 207165 次
来自: 上海
多谢楼主配对那一段,解决了我的大问题啊
这个反射的createBond用法很有意思这个代码能像非and ...
例子还是短小看着一目了然。不错
在WEB中,是使用WebApplicationContext的 ...
请问一下楼主,这个UUID是不是和设备有关啊,我使用你的 co ...

我要回帖

更多关于 蓝牙uuid是什么 的文章

 

随机推荐