Android获取已连接远程蓝牙设备地址问题

zaijzhgh 2013-12-31 09:15:31
最近在做一个关于蓝牙设备的东西, 遇到一个问题: 使用手机和一个远程的蓝牙设备匹配并连接好之后, 这时候再启动我写的app, 那么我如何在App中获取已经匹配并连接好的远程蓝牙设备的MAC地址呢.
谢谢了.
...全文
2237 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
紫金侠 2016-03-31
  • 打赏
  • 举报
回复
感觉不错,有帮助
江一柠Joy 2015-04-03
  • 打赏
  • 举报
回复
楼主 这个可以把这些代码分享给我吗 我不知道 reConnectDevice方法怎么写 而且一些变量是怎么定义的
behappy0_o 2014-11-14
  • 打赏
  • 举报
回复
reConnectDevice 在哪里
fhzhang 2014-09-09
  • 打赏
  • 举报
回复
Sorry!, It's OK! 没问题,搞定,谢谢!
fhzhang 2014-09-09
  • 打赏
  • 举报
回复

没反应,onServiceConnected函数没有执行啦!楼主搞定了吗?
vsjkai 2014-05-28
  • 打赏
  • 举报
回复
非常感谢,正是需要的。
逆风而行 2014-01-10
  • 打赏
  • 举报
回复
最近也在做这个东西就分享给你吧,如果你的程序是在连接上之后启动的,你最好使用如下方式获取已连接的蓝牙地址: BluetoothAdapter _blueAdapter = BluetoothAdapter.getDefaultAdapter(); //注册a2dp监听 _blueAdapter.getProfileProxy(_mParent,proxyListener,BluetoothProfile.A2DP); private BluetoothProfile.ServiceListener proxyListener = new BluetoothProfile.ServiceListener(){ @Override public void onServiceConnected(int profile, BluetoothProfile proxy) { // TODO Auto-generated method stub SLog.Log('w',TAG,"BluetoothProfile profile: " + profile); if (proxy != null){ List<BluetoothDevice> cd = proxy.getConnectedDevices(); if (cd != null){ SLog.Log('w',TAG,"BluetoothDevice size: " + cd.size()); for (int i = 0 ; i < cd.size(); i++){ BluetoothDevice t = cd.get(i); SLog.Log('w',TAG,"BluetoothDevice : " + t.getName() + "|" + t.getAddress() ); if (reConnectDevice(t.getAddress())){ SLog.Log('w',TAG,"select BluetoothDevice : " + t.getName() + "|" + t.getAddress() + " connect sucess"); break; } } } } } @Override public void onServiceDisconnected(int profile) { // TODO Auto-generated method stub } }; 如果是蓝牙A2dp后连接的你最好接收下BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED广播 如下处理: else if (BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED.equalsIgnoreCase(action)){ BluetoothDevice mdevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); int istate = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1); int newState = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, 0); SLog.Log('w',TAG, "BluetoothA2dp ACTION_CONNECTION_STATE_CHANGED :" + istate + "|" + newState + "," + mdevice); if (mdevice != null){ checkBlueToothA2dpState(mdevice,istate); } }

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧