支持安卓系统的蓝牙蓝牙咋样把被查找修改为查找~~~~??

Android 蓝牙 启动、可见性设置、搜索、配对、通讯过程-linux-电脑编程网Android 蓝牙 启动、可见性设置、搜索、配对、通讯过程作者:佚名 和相关&&//开启蓝牙功能& & & & & & myButton = (Button)findViewById(R.id.Button_1);& & & & myButton.setOnClickListener(new OnClickListener() {& & & & & & & & & & & &&& & & & & & & & & & & & public void onClick(View v) {& & & & & & & & & & & & & & & & // TODO Auto-generated method stub& & & & & & & & & & & & & & & & //得到BluetoothAdapter对象& & & & & & & & & & & & & & & & BluetoothAdapter adapter =BluetoothAdapter.getDefaultAdapter();& & & & & & & & & & & & & & & & //判断BluetoothAdapter对象是否为空,为空,则表明本机没有蓝牙设备& & & & & & & & & & & & & & & & if(null != adapter){& & & & & & & & & & & & & & & & & & & & System.out.println("本机拥有蓝牙设备");& & & & & & & & & & & & & & & & & & & & //判断蓝牙是否可用& & & & & & & & & & & & & & & & & & & & if(!adapter.isEnabled()){& & & & & & & & & & & & & & & & & & & & & & & & //创建一个intent对象,感对象用于启动一个Activity,提示用户开启蓝牙设备& & & & & & & & & & & & & & & & & & & & & & & & Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);& & & & & & & & & & & & & & & & & & & & & & & & startActivity(intent);& & & & & & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & & & & & //迭代,得到所有已经配对的蓝牙适配器对象, 本机已保存的配对信息。& & & & & & & & & & & & & & & & & & & & Set&BluetoothDevice& devices = adapter.getBondedDevices();& & & & & & & & & & & & & & & & & & & & if(devices.size() & 0){& & & & & & & & & & & & & & & & & & & & & & & & for(Iterator iterator = devices.iterator(); iterator.hasNext(); ){& & & & & & & & & & & & & & & & & & & & & & & & & & & & BluetoothDevice bluetoothDevice = (BluetoothDevice)iterator.next();& & & & & & & & & & & & & & & & & & & & & & & & & & & & System.out.println(bluetoothDevice.getAddress()+ "----" +bluetoothDevice.getName());& & & & & & & & & & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & & }else{& & & & & & & & & & & & & & & & & & & & System.out.println("本机没有蓝牙设备");& & & & & & & & & & & & & & & & }& & & & & & & & & & & & }& & & & & & & & });& & & &&& & & &&& & & & //设置蓝牙可见& & & & myButton2 = (Button)findViewById(R.id.Button_2);& & & & myButton2.setOnClickListener(new OnClickListener() {& & & & & & & & & & & &&& & & & & & & & & & & & public void onClick(View v) {& & & & & & & & & & & & & & & & // TODO Auto-generated method stub& & & & & & & & & & & & & & & & //创建Intent对象,并将其Action的值设置为& & & & & & & & & & & & & & & & Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);& & & & & & & & & & & & & & //讲一个键值对对方到Intent对象当中,用于指定可见状态的持续时间& & & & & & & & & & & & & & & & discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);& & & & & & & & & & & & & & startActivity(discoverableIntent);& & & & & & & & & & & & & &&& & & & & & & & & & & & }& & & & & & & & });& & & &&& & & &&& & & &&& & & & myButton3 = (Button)findViewById(R.id.Button_3);& & & & myButton3.setOnClickListener(new OnClickListener() { & & & && & & & & & & & & & & & public void onClick(View v) {& & & & & & & & & & & & & & & & // TODO Auto-generated method stub& & & & & & & & & & & & & & & &&& & & & & & & & & & & & & & & & str = "";& & & & & & & & & & & & & & & & //广播监听& & & & & & & & & & & & IntentFilter intentfilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);& & & & & & & & & & & & bluetoothReceiver = new BluetoothReceiver();& & & & & & & & & & & & registerReceiver(bluetoothReceiver, intentfilter);& & & & & & & & & & & & & & & & BluetoothAdapter adapter =BluetoothAdapter.getDefaultAdapter();& & & & & & & & & & & & & & & & adapter.startDiscovery();& & & & & & & & & & & & & & & &&& & & & & & & & & & & & }& & & & & & & & });& & & &&& & & & myButton4 = (Button)this.findViewById(R.id.Button_4);& & & & myButton4.setOnClickListener(new OnClickListener() {& & & & & & & & & & & &&& & & & & & & & & & & & public void onClick(View v) {& & & & & & & & & & & & & & & & // TODO Auto-generated method stub& & & & & & & & & & & & & & & &&& & & & & & & & & & & & & & & & String address = "00:10:10:22:02:72"; & //电脑MAC&& & & & & & & & & & & & & & & & UUID uuid = UUID.fromString(SPP_UUID); && & & & & & & & & & & & & & & & //创建adapter对象& & & & & & & & & & & & & & & & BluetoothAdapter adapter =BluetoothAdapter.getDefaultAdapter();& & & & & & & & & & & & & & & & //通过MAC地址创建BluetoothDevice对象& & & & & & & & & & & & & & & & BluetoothDevice btDev = adapter.getRemoteDevice(address);& & & & & & & & & & & & & & & &&& & & & & & & & & & & & & & & & try {& & & & & & & & & & & & & & & & & & & & btSocket = btDev.createRfcommSocketToServiceRecord(uuid);& & & & & & & & & & & & & & & & & & & & btSocket.connect();& & & & & & & & & & & & & & & & & & & & System.out.println("----"+btSocket.getRemoteDevice().toString());& & & & & & & & & & & & & & & & } catch (IOException e) {& & & & & & & & & & & & & & & & & & & & // TODO Auto-generated catch block& & & & & & & & & & & & & & & & & & & & e.printStackTrace();& & & & & & & & & & & & & & & & & & & & System.out.println("创建RFCOM出错");& & & & & & & & & & & & & & & & }& & & & & & & & & & & & & & & &&& & & & & & & & & & & & & & & & InputStream is =& & & & & & & & & & & & & & & & OutputStream os =& & & & & & & & & & & & & & & &&& & & & & & & & & & & & & & & & try {& & & & & & & & & & & & is = btSocket.getInputStream();& & & & & & & & & & & & os = btSocket.getOutputStream();& & & & & & & & & & } catch (IOException e) {& & & & & & & & & & & & & & e.printStackTrace();& & & & & & & & & & & & & & System.out.println("???????");& & & & & & & & & & }& & & & & & & & & &&& & & & & & & & & & String message = "";& & & & & & & & & & byte[] send = message.getBytes();& & & & & & & & & &&& & & & & & & & & & try{& & & & & & & & & & & & & & os.write(send);& & & & & & & & & & } catch(IOException e) {& & & & & & & & & & & & & & e.printStackTrace();& & & & & & & & & & & & & & System.out.println("输出时出现异常");& & & & & & & & & & }& & & & & & & & & & & & }& & & & & & & & });& & & &&& & }& &&& & //广播监听类& & private class BluetoothReceiver extends BroadcastReceiver{& & & & & & & & @Override& & & & & & & & public void onReceive(Context context, Intent intent) {& & & & & & & & & & & & // TODO Auto-generated method stub& & & & & & & & & & & & String action = intent.getAction();& & & & & & & & & & & & if(BluetoothDevice.ACTION_FOUND.equals(action)){& & & & & & & & & & & & & & & & BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);& & & & & & & & & & & & & & System.out.println(device.getName()+"----"+device.getAddress());& & & & & & & & & & & & & &&& & & & & & & & & & & & & & str += device.getName()+"----"+device.getAddress() + "\n";& & & & & & & & & & & & & & myTextView.setText(str);& & & & & & & & & & & & & &&& & & & & & & & & & & & }& & & & & & & & }& & & & & &&& & }}/*&* 未开启蓝牙功能的时候仍然能够得到已经配对的蓝牙的信息&* 已配对的蓝牙设备的信息已经存储在了手机里,但是不能进行连接操作&*&&*/相关资料:|||||||Android 蓝牙 启动、可见性设置、搜索、配对、通讯过程来源网络,如有侵权请告知,即处理!编程Tags:                &                    怎么在安卓手机上找到安装的文件从蓝牙发送出去_百度知道
怎么在安卓手机上找到安装的文件从蓝牙发送出去
自己手机上安装的游戏,想在手机里找到文件经蓝牙发送另一个手机上大神求解,需要说的详细点的
app下可以找到安装的程序root以后用re管理器之类的高权限文件管理器;data&#47,可以通过wifi传文件,速度可以达到几兆&#47,到&#47、茄子快传之类的软件,然后就可以用蓝牙发送不过更方便的还是用快牙、闪传
其他类似问题
为您推荐:
其他2条回答
后辍名为安装的完文件是不能出去的,你要找到安装包,用文件管理器找.apk
如果对方的手机也是安卓系统能装“快牙”,就可以不用蓝牙,用“快牙”可以传已经安装的文件。你在百度里面搜搜。有很多。
安卓手机的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁安卓手机的蓝牙在哪啊?怎么找不到_百度知道
安卓手机的蓝牙在哪啊?怎么找不到
我有更好的答案
当然,不知道你的是什么机型,一般的智能机都有蓝牙,第二个就是蓝牙了,第一个是WLAN下拉状态栏
都是按手机品牌,与系统无关
设置菜单里面
其他类似问题
为您推荐:
您可能关注的推广回答者:
安卓手机的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁Android 蓝牙设备的查找和连接_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Android 蓝牙设备的查找和连接
来源:Linux社区&
作者:cat9101983
1.权限使用蓝牙设备需要先在Manifest中开放权限,位置如下。
&...&&&&&&&&
&&&&&...&&
&&&&&&&&&&&...&&
&&&&//&使用蓝牙设备的权限&&
&&&&&:name="android.permission.BLUETOOTH"&&&
&&&&//&管理蓝牙设备的权限&&
&&&&&android:name="android.permission.BLUETOOTH_ADMIN"&&&
&&2.打开蓝牙获得蓝牙适配器(android.bluetooth.BluetoothAdapter),检查该设备是否支持蓝牙,如果支持,就打开蓝牙。
adapter&=&BluetoothAdapter.getDefaultAdapter();&&
if&(adapter&==&null)&&
if&(!adapter.isEnabled())&&
&&&&Intent&intent&=&new&Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);&&
&&&&intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,&<FONT color=#c);&&
&&&&context.startActivity(intent);&&
}&&3.获取已配对的蓝牙设备(android.bluetooth.BluetoothDevice)首次连接某蓝牙设备需要先配对,一旦配对成功,该设备的信息会被保存,以后连接时无需再配对,所以已配对的设备不一定是能连接的。
BluetoothAdapter&adapter&=&BluetoothAdapter.getDefaultAdapter();&&
Set&BluetoothDevice&&devices&=&adapter.getBondedDevices();&&
for(int&i=0;&i&devices.size();&i++)&&
&&&&BluetoothDevice&device&=&(BluetoothDevice)&devices.iterator().next();&&
&&&&System.out.println(device.getName());&&
}&&4.搜索周围的蓝牙设备适配器搜索蓝牙设备后将结果以广播形式传出去,所以需要自定义一个继承广播的类,在onReceive方法中获得并处理蓝牙设备的搜索结果。
IntentFilter&intentFilter&=&new&IntentFilter();&&
intentFilter.addAction(BluetoothDevice.ACTION_FOUND);&&
intentFilter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);&&
intentFilter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);&&
intentFilter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);&&
context.registerReceiver(receiver,&intentFilter);&&
adapter.startDiscovery();&&自定义广播类
private&BroadcastReceiver&receiver&=&new&BroadcastReceiver()&{&&
&&&@Override&&
&&&public&void&onReceive(Context&context,&Intent&intent)&{&&
&&&&&&&&String&action&=&intent.getAction();&&
&&&&&&&&if&(BluetoothDevice.ACTION_FOUND.equals(action))&{&&
&&&&&&&&&&&&BluetoothDevice&device&=&intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);&&
&&&&&&&&&&&&System.out.println(device.getName());&&
&&&&&&&&}&&
}&&5.蓝牙设备的配对和状态监视
private&BroadcastReceiver&receiver&=&new&BroadcastReceiver()&{&&
&&&&@Override&&
&&&&public&void&onReceive(Context&context,&Intent&intent)&{&&
&&&&&&&&String&action&=&intent.getAction();&&
&&&&&&&&if&(BluetoothDevice.ACTION_FOUND.equals(action))&{&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&BluetoothDevice&device&=&intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);&&
&&&&&&&&&&&&System.out.println(device.getName());&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&if&(device.getName().equalsIgnoreCase(name))&{&&
&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&adapter.cancelDiscovery();&&
&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&connectState&=&device.getBondState();&&
&&&&&&&&&&&&&&&&switch&(connectState)&{&&
&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&BluetoothDevice.BOND_NONE:&&
&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&Method&createBondMethod&=&BluetoothDevice.class.getMethod("createBond");&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&createBondMethod.invoke(device);&&
&&&&&&&&&&&&&&&&&&&&&&&&}&catch&(Exception&e)&{&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&&&&&break;&&
&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&case&BluetoothDevice.BOND_BONDED:&&
&&&&&&&&&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&connect(device);&&
&&&&&&&&&&&&&&&&&&&&&&&&}&catch&(IOException&e)&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&&&&&break;&&
&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&}&&
&&&&&&&}&else&if(BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action))&{&&
&&&&&&&&&&&&&&
&&&&&&&&&&&&BluetoothDevice&device&=&intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);&&
&&&&&&&&&&&&if&(device.getName().equalsIgnoreCase(name))&{&&&
&&&&&&&&&&&&&&&&connectState&=&device.getBondState();&&
&&&&&&&&&&&&&&&&switch&(connectState)&{&&
&&&&&&&&&&&&&&&&&&&&case&BluetoothDevice.BOND_NONE:&&
&&&&&&&&&&&&&&&&&&&&&&&&break;&&
&&&&&&&&&&&&&&&&&&&&case&BluetoothDevice.BOND_BONDING:&&
&&&&&&&&&&&&&&&&&&&&&&&&break;&&
&&&&&&&&&&&&&&&&&&&&case&BluetoothDevice.BOND_BONDED:&&
&&&&&&&&&&&&&&&&&&&&&&&&try&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&connect(device);&&
&&&&&&&&&&&&&&&&&&&&&&&&}&catch&(IOException&e)&{&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&e.printStackTrace();&&
&&&&&&&&&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&&&&&&&&&&&&&break;&&
&&&&&&&&&&&&&&&&}&&
&&&&&&&&&&&&}&&
&&&&&&&&}&&
}&&6.蓝牙设备的连接
private&void&connect(BluetoothDevice&device)&throws&IOException&{&&
&&&&final&String&SPP_UUID&=&"0-805F9B34FB";&&
&&&&UUID&uuid&=&UUID.fromString(SPP_UUID);&&
&&&&BluetoothSocket&socket&=&device.createRfcommSocketToServiceRecord(uuid);&&
&&&&socket.connect();&&
相关资讯 & & &
& (03/23/:55)
& (02/17/:44)
& (02/17/:53)
& (02/17/:45)
& (02/17/:52)
& (02/17/:45)
图片资讯 & & &
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款安卓系统有没有查找i phone_百度知道
安卓系统有没有查找i phone
蓝牙可搜索,不支持传输文件的哦,你也知道的嘛~~苹果是全封闭的系统,和其他软件商不对路~·望采纳
其他类似问题
为您推荐:
安卓系统的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 安卓系统蓝牙驱动下载 的文章

 

随机推荐