歌华机顶盒蓝牙配对上开发蓝牙功能,删除掉源生的Settings时,打开蓝牙,允许检测,和配对都会报错,请各位大神指点

机顶盒上开发蓝牙功能,删除掉源生的Settings时,打开蓝牙,允许检测,和配对都会报错,请各位大神指点_ZNDS网友问答
只需一步,快速开始
扫一扫,访问微社区
后使用快捷导航没有帐号?
TV应用下载 / 资源分享区
综合交流 / 产品评测 / 活动公告
新手入门 / 社区互助
查看: 271|回复: 0
机顶盒上开发蓝牙功能,删除掉源生的Settings时,打开蓝牙,允许检测,和配对都会报错,请各位大神指点
您需要登录后才可以回帖
回帖并转播
强烈推荐,装机必备软件!专为智能电视和安卓电视盒子打造的TV APP应用商店!追求极简体验,完美适配遥控器!海量精选TV应用,快下载体验吧!
电视运行慢,看视频卡、玩游戏卡、用浏览器还是卡,卡的人想砸电视怎么办?别担心,当贝助手来帮您!当贝助手,第一款专为电视打造的功能全面的当贝电视管家!
倡导极简高效的电视主题桌面,极致的自主操作和用户体验。并提供智能排序、自动清理、快捷管理等一系列贴心功能,帮助用户让智能电视变得真正简单好用。
没有你搜不到的影片!集点播直播一体,智能电视必备软件,覆盖全网的99%视频资源,电影电视、综艺动漫、教育体育等,你想看的都在这里!
增值电信业务经营许可证:浙B2- 丨 杭州市公安局滨江分局备案编号:71
Powered by Discuz!
监督举报: (请将#替换为@)android 取消蓝牙配对框 实现自动配对
我看了几个文章,主要是接受配对广播,然后设置pin,实现配对,但是网上的大部分手机是不可以的,android.bluetoothdevice 下 action_pair_request ,没有定义这个,开始困扰了我一点时间,实现难度:是否能进入那个广播响应
定义了一个类,这个是网上的可以直接用
package zicox.&
import java.lang.reflect.M&
import java.lang.reflect.F&
import android.bluetooth.BluetoothA&
import android.bluetooth.BluetoothD&
import android.util.L&
public class ClsUtils&&
&&&& * 与设备配对 参考:platform/packages/apps/Settings.git
&&&& * /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
&&& static public boolean createBond(Class btClass, BluetoothDevice btDevice)&
&&& throws Exception&
&&&&&&& Method createBondMethod = btClass.getMethod(&createBond&);&
&&&&&&& Boolean returnValue = (Boolean) createBondMethod.invoke(btDevice);&
&&&&&&& return returnValue.booleanValue();&
&&&& * 与设备解除配对 参考源码:platform/packages/apps/Settings.git
&&&& * /Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
&&& static public boolean removeBond(Class btClass, BluetoothDevice btDevice)&
&&&&&&&&&&& throws Exception&
&&&&&&& Method removeBondMethod = btClass.getMethod(&removeBond&);&
&&&&&&& Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice);&
&&&&&&& return returnValue.booleanValue();&
&&& static public boolean setPin(Class btClass, BluetoothDevice btDevice,&
&&&&&&&&&&& String str) throws Exception&
&&&&&&& try&
&&&&&&& {&
&&&&&&&&&&& Method removeBondMethod = btClass.getDeclaredMethod(&setPin&,&
&&&&&&&&&&&&&&&&&&& new Class[]&
&&&&&&&&&&&&&&&&&&& {byte[].class});&
&&&&&&&&&&& Boolean returnValue = (Boolean) removeBondMethod.invoke(btDevice,&
&&&&&&&&&&&&&&&&&&& new Object[]&
&&&&&&&&&&&&&&&&&&& {str.getBytes()});&
&&&&&&&&&&& Log.e(&returnValue&, && + returnValue);&
&&&&&&& }&
&&&&&&& catch (SecurityException e)&
&&&&&&& {&
&&&&&&&&&&& // throw new RuntimeException(e.getMessage());&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&&&&&& catch (IllegalArgumentException e)&
&&&&&&& {&
&&&&&&&&&&& // throw new RuntimeException(e.getMessage());&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&&&&&& catch (Exception e)&
&&&&&&& {&
&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&& // 取消用户输入&
&&& static public boolean cancelPairingUserInput(Class btClass,&
&&&&&&&&&&& BluetoothDevice device)&
&&& throws Exception&
&&&&&&& Method createBondMethod = btClass.getMethod(&cancelPairingUserInput&);&
&&&&&&& // cancelBondProcess()&
&&&&&&& Boolean returnValue = (Boolean) createBondMethod.invoke(device);&
&&&&&&& return returnValue.booleanValue();&
&&& // 取消配对&
&&& static public boolean cancelBondProcess(Class btClass,&
&&&&&&&&&&& BluetoothDevice device)&
&&& throws Exception&
&&&&&&& Method createBondMethod = btClass.getMethod(&cancelBondProcess&);&
&&&&&&& Boolean returnValue = (Boolean) createBondMethod.invoke(device);&
&&&&&&& return returnValue.booleanValue();&
&&&& * @param clsShow
&&& static public void printAllInform(Class clsShow)&
&&&&&&& try&
&&&&&&& {&
&&&&&&&&&&& // 取得所有方法&
&&&&&&&&&&& Method[] hideMethod = clsShow.getMethods();&
&&&&&&&&&&& int i = 0;&
&&&&&&&&&&& for (; i & hideMethod. i++)&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& Log.e(&method name&, hideMethod[i].getName() + &;and the i is:&&
&&&&&&&&&&&&&&&&&&&&&&& + i);&
&&&&&&&&&&& }&
&&&&&&&&&&& // 取得所有常量&
&&&&&&&&&&& Field[] allFields = clsShow.getFields();&
&&&&&&&&&&& for (i = 0; i & allFields. i++)&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& Log.e(&Field name&, allFields[i].getName());&
&&&&&&&&&&& }&
&&&&&&& }&
&&&&&&& catch (SecurityException e)&
&&&&&&& {&
&&&&&&&&&&& // throw new RuntimeException(e.getMessage());&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&&&&&& catch (IllegalArgumentException e)&
&&&&&&& {&
&&&&&&&&&&& // throw new RuntimeException(e.getMessage());&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&&&&&& catch (Exception e)&
&&&&&&& {&
&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&& e.printStackTrace();&
&&&&&&& }&
&&& static public boolean pair(String strAddr, String strPsw)&
&&&&&&& boolean result =&
&&&&&&& BluetoothAdapter bluetoothAdapter = BluetoothAdapter&
&&&&&&&&&&&&&&& .getDefaultAdapter();&
&&&&&&& bluetoothAdapter.cancelDiscovery();&
&&&&&&& if (!bluetoothAdapter.isEnabled())&
&&&&&&& {&
&&&&&&&&&&& bluetoothAdapter.enable();&
&&&&&&& }&
&&&&&&& if (!BluetoothAdapter.checkBluetoothAddress(strAddr))&
&&&&&&& { // 检查蓝牙地址是否有效&
&&&&&&&&&&& Log.d(&mylog&, &devAdd un effient!&);&
&&&&&&& }&
&&&&&&& BluetoothDevice device = bluetoothAdapter.getRemoteDevice(strAddr);&
&&&&&&& if (device.getBondState() != BluetoothDevice.BOND_BONDED)&
&&&&&&& {&
&&&&&&&&&&& try&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& Log.d(&mylog&, &NOT BOND_BONDED&);&
&&&&&&&&&&&&&&& ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对&
&&&&&&&&&&&&&&& ClsUtils.createBond(device.getClass(), device);&
//&&&&&&&&&&&&&&& remoteDevice = // 配对完毕就把这个设备对象传给全局的remoteDevice&
&&&&&&&&&&&&&&& result =&
&&&&&&&&&&& }&
&&&&&&&&&&& catch (Exception e)&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&&&&&& Log.d(&mylog&, &setPiN failed!&);&
&&&&&&&&&&&&&&& e.printStackTrace();&
&&&&&&&&&&& } //&
&&&&&&& }&
&&&&&&& else&
&&&&&&& {&
&&&&&&&&&&& Log.d(&mylog&, &HAS BOND_BONDED&);&
&&&&&&&&&&& try&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& ClsUtils.createBond(device.getClass(), device);&
&&&&&&&&&&&&&&& ClsUtils.setPin(device.getClass(), device, strPsw); // 手机和蓝牙采集器配对&
&&&&&&&&&&&&&&& ClsUtils.createBond(device.getClass(), device);&
//&&&&&&&&&&&&&&& remoteDevice = // 如果绑定成功,就直接把这个设备对象传给全局的remoteDevice&
&&&&&&&&&&&&&&& result =&
&&&&&&&&&&& }&
&&&&&&&&&&& catch (Exception e)&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&&&&&& Log.d(&mylog&, &setPiN failed!&);&
&&&&&&&&&&&&&&& e.printStackTrace();&
&&&&&&&&&&& }&
&&&&&&& }&
//================================================================================================================================
还有一部分 activity
//================================================================================================================================
package zicox.&
import java.io.IOE&
import java.io.UnsupportedEncodingE&
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 Demo_ad_escActivity extends Activity&
&&& //---------------------------------------------------&
&&& public static String ErrorM&
&&& 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);&
&&&&& //& if(!ListBluetoothDevice())finish();&
&&&&&&& Button Button1 = (Button) findViewById(R.id.button1);&
&&&&&&& ErrorMessage = &&;&
&&&&&&& //---------------------------------------------------&
&&&&&&& 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.toggleButton1);&&&
&&&&&&& tbtnSwitch.setOnClickListener(new ClickEvent());&
&&&&&&& // ListView及其数据源 适配器&&&
&&&&&&& lvBTDevices = (ListView) this.findViewById(R.id.listView1);&&&
&&&&&&& adtDevices = new ArrayAdapter&String&(this,&&&
&&&&&&&&&&&&&&& android.R.layout.simple_list_item_1, lstDevices);&&&
&&&&&&& lvBTDevices.setAdapter(adtDevices);&&&
&&&&&&& lvBTDevices.setOnItemClickListener(new ItemClickEvent());&&&
&&&&&&& btAdapt = BluetoothAdapter.getDefaultAdapter();// 初始化本机蓝牙功能&&&
&&&&&&& if (btAdapt.isEnabled())&&
&&&&&&&&&&& tbtnSwitch.setChecked(false);&&&
&&&&&&& else&&
&&&&&&&&&&& tbtnSwitch.setChecked(true);&&&&&
&&&&&&&&& // 注册Receiver来获取蓝牙设备相关的结果&&
&&&&&&& String ACTION_PAIRING_REQUEST = &android.bluetooth.device.action.PAIRING_REQUEST&;&
&&&&&&& IntentFilter intent = new IntentFilter();&&&
&&&&&&& intent.addAction(BluetoothDevice.ACTION_FOUND);// 用BroadcastReceiver来取得搜索结果&&&
&&&&&&& intent.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);&&&
&&&&&&& intent.addAction(ACTION_PAIRING_REQUEST);&
&&&&&&& intent.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);&&&
&&&&&&& intent.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);&&&
&&&&&&& registerReceiver(searchDevices, intent);&&&
&&&&&&& Button1.setOnClickListener(new Button.OnClickListener()&
&&&&&&& {&
&&&&&&&&&&& public void onClick(View arg0)&
&&&&&&&&&&& {&
&&& //&&&&&&&&& Print1(SelectedBDAddress);&
&&&&&&&&&&& }&
&&&&&&& });&
//---------------------------------------------------&
&&& 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();&&
&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&& try {&
&&&&&&&&&&&&&&&&&&&&&&& ClsUtils.setPin(device.getClass(),device,&0000&);&
&&&&&&&&&&&&&&&&&&& } catch (Exception e) {&
&&&&&&&&&&&&&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&&&&&&&&&&&&&& e.printStackTrace();&
&&&&&&&&&&&&&&&&&&& }&
&&&&&&&&&&&&&&&&&&& try {&
&&&&&&&&&&&&&&&&&&&&&&& ClsUtils.cancelPairingUserInput(device.getClass(), device);&
&&&&&&&&&&&&&&&&&&& } catch (Exception e) {&
&&&&&&&&&&&&&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&&&&&&&&&&&&&& e.printStackTrace();&
&&&&&&&&&&&&&&&&&&& }&
&&&&&&&&&&&&&&& }&&&
&&&&&&&&&&& }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&, &取消配对&);&&&
&&&&&&&&&&&&&&& default:&&&
&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }&&&
&&&&&&&&&&& }&&&
&&&&&&&&&&&&&
&&&&&&&&&&&&&
&&&&&&&&&&& if (intent.getAction().equals(&android.bluetooth.device.action.PAIRING_REQUEST&))&
&&&&&&&&&&& {&
&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& Log.e(&tag&, &ddd&);&
&&&&&&&&&&&&&&& BluetoothDevice btDevice = intent&
&&&&&&&&&&&&&&&&&&&&&&& .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);&
&&&&&&&&&&&&&&& // byte[] pinBytes = BluetoothDevice.convertPinToBytes(&1234&);&
&&&&&&&&&&&&&&& // device.setPin(pinBytes);&
&&&&&&&&&&&&&
&&&&&&&&&&&&&&& try&
&&&&&&&&&&&&&&& {&
&&&&&&&&&&&&&&&&&&& ClsUtils.setPin(btDevice.getClass(), btDevice, &0000&); // 手机和蓝牙采集器配对&
&&&&&&&&&&&&&&&&&&& ClsUtils.createBond(btDevice.getClass(), btDevice);&
&&&&&&&&&&&&&&&&&&& ClsUtils.cancelPairingUserInput(btDevice.getClass(), btDevice);&
&&&&&&&&&&&&&&& }&
&&&&&&&&&&&&&&& catch (Exception e)&
&&&&&&&&&&&&&&& {&
&&&&&&&&&&&&&&&&&&& // TODO Auto-generated catch block&
&&&&&&&&&&&&&&&&&&& e.printStackTrace();&
&&&&&&&&&&&&&&& }&
&&&&&&&&&&& }&
&&&&&&& }&
&&& class ItemClickEvent implements AdapterView.OnItemClickListener {&&&
&&&&&&&&&&&
&&&&&&& @Override&&&
&&&&&&& 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);&&&
&&&&&&&&&&& try {&&&
&&&&&&&&&&&&&&& 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);&&&
&&&&&&&&&&&&&&&&&&& ClsUtils.pair(address, &0000&);&
&&&&&&&&&&&&&&&&&&& showMessage(&here&);&
&&&&&&&&&&&&&&& }else if(btDev.getBondState() == BluetoothDevice.BOND_BONDED){&&&
&&&&&&&&&&&&&&&&&&& connect(btDev);&&&
&&&&&&&&&&&&&&& }&&&
&&&&&&&&&&& } catch (Exception e) {&&&
&&&&&&&&&&&&&&& e.printStackTrace();&&&
&&&&&&&&&&& }&&&
&&&&&&& }&&&
&&& private void connect(BluetoothDevice btDev) {&&
&&&&&&& final UUID SPP_UUID = UUID.fromString(&0-805F9B34FB&);&
&&&&&&& UUID uuid = SPP_UUID;&&&
&&&&&&& try {&&&
&&&&&&&&&&& btSocket = btDev.createRfcommSocketToServiceRecord(uuid);&&&
&&&&&&&&&&& Log.d(&BlueToothTestActivity&, &开始连接...&);&&&
&&&&&&&&&&& btSocket.connect();&&&
&&&&&&& } catch (IOException e) {&&&
&&&&&&&&&&& // TODO Auto-generated catch block&&&
&&&&&&&&&&& e.printStackTrace();&&&
&&&&&&& }&&&
&&& class ClickEvent implements View.OnClickListener {&&&
&&&&&&& @Override&&&
&&&&&&& public void onClick(View v) {&&&
&&&&&&&&&&& if (v == btnSearch)// 搜索蓝牙设备,在BroadcastReceiver显示结果&&&
&&&&&&&&&&& {&&&
&&&&&&&&&&&&&&& if (btAdapt.getState() == BluetoothAdapter.STATE_OFF) {// 如果蓝牙还没开启&&&
&&&&&&&&&&&&&&&&&&& Toast.makeText(Demo_ad_escActivity.this, &请先打开蓝牙&, 1000).show();&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&& }&&&
&&&&&&&&&&&&&&& 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) {&&&
&&&&&&&&&&&&&&& try {&&&
&&&&&&&&&&&&&&&&&&& if (btSocket != null)&&&
&&&&&&&&&&&&&&&&&&&&&&& btSocket.close();&&&
&&&&&&&&&&&&&&& } catch (IOException e) {&&&
&&&&&&&&&&&&&&&&&&& e.printStackTrace();&&&
&&&&&&&&&&&&&&& }&&&
&&&&&&&&&&&&&&& Demo_ad_escActivity.this.finish();&&&
&&&&&&&&&&& }&&&
&&&&&&& }&&&
&&& @Override&&&
&&& protected void onDestroy() {&&&
&&&&&&& this.unregisterReceiver(searchDevices);&&&
&&&&&&& super.onDestroy();&&&
&&&&&&& android.os.Process.killProcess(android.os.Process.myPid());&&&
&&& public void showMessage(String str)&
&&&&&&& Toast.makeText(this,str, Toast.LENGTH_LONG).show();&
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'}

我要回帖

更多关于 该远程设备不允许配对 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信