换手机了,原手机配对的蓝牙连接怎样清除蓝牙配对记录

上一篇: 下一篇:
相关资讯:
推荐单品:android手机与其他手机的蓝牙连接 -
- ITeye技术网站
博客分类:
//本程序连接必须自己先在手机上与对方配对然后再运行这个程序....
public class BluetoothComActivity extends Activity {
/** Called when the activity is first created. */ private BluetoothDevice[] foundDevice = new BluetoothDevice[3]; private CharSequence[] DeviceName = new CharSequence[3]; BluetoothAdapter bA private int DISCOVERY_REQUEST = 1; private UUID uuid = UUID.fromString("0-805F9B34FB");//文件交换型UUID,
//需要其他类型的UUID就自己去查表,或者是服务器,客户端都是自己写,那有就你自己定一个公用的UUID
private BluetoothSocket bS private String bluetoothN private String bluetoothA ArrayA ListV int DeviceN
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
bAdapter = BluetoothAdapter.getDefaultAdapter();
//-------------开启蓝牙前准备---------------------
//-------------蓝牙状态广播接收器-------------------------------------
BroadcastReceiver bluetoothState = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String preStateExtra = BluetoothAdapter.EXTRA_PREVIOUS_STATE;
String stateExtra = BluetoothAdapter.EXTRA_STATE;
int state = intent.getIntExtra(stateExtra, -1);
int previousState = intent.getIntExtra(preStateExtra, -1);
switch(state){
case (BluetoothAdapter.STATE_TURNING_ON):
Toast.makeText(BluetoothComActivity.this,"Bluetooth trun on!", Toast.LENGTH_SHORT).show();
case (BluetoothAdapter.STATE_ON):
Toast.makeText(BluetoothComActivity.this,"Bluetooth state on!", Toast.LENGTH_SHORT).show();
bluetoothName = bAdapter.getName();
bluetoothAddress = bAdapter.getAddress();
System.out.println(bluetoothName);
System.out.println(bluetoothAddress);
//---------开始扫描---------------------------------------------------------
bAdapter.startDiscovery();
case (BluetoothAdapter.STATE_TURNING_OFF):
Toast.makeText(BluetoothComActivity.this,"Bluetooth state trun off!", Toast.LENGTH_SHORT).show();
case (BluetoothAdapter.STATE_OFF):
Toast.makeText(BluetoothComActivity.this,"Bluetooth off!", Toast.LENGTH_SHORT).show();
//----------开启蓝牙-------------------------------------------------
if(!bAdapter.isEnabled()){
String actionStateChange = BluetoothAdapter.ACTION_STATE_CHANGED;
String actionStateEnable = BluetoothAdapter.ACTION_REQUEST_ENABLE;
registerReceiver(bluetoothState, new IntentFilter(actionStateChange));
startActivityForResult(new Intent(actionStateEnable), 0);
//while(!bAdapter.isEnabled());
//---------扫描蓝牙设备前准备(作为主机)------------------------------------------------
//String discoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
//startActivityForResult(new Intent(discoverable), DISCOVERY_REQUEST);
//---------扫描过程广播监听--------------------------------------------------
BroadcastReceiver discoveryReceiver = new BroadcastReceiver(){
String aStarted = BluetoothAdapter.ACTION_DISCOVERY_STARTED;
String aFinished= BluetoothAdapter.ACTION_DISCOVERY_FINISHED;
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(aStarted.equals(intent.getAction())){
Toast.makeText(BluetoothComActivity.this,"Discovery Start......", Toast.LENGTH_SHORT).show();
System.out.println("开始扫描!");
if(aFinished.equals(intent.getAction())){
Toast.makeText(BluetoothComActivity.this,"Discovery Finish......", Toast.LENGTH_SHORT).show();
System.out.println("结束扫描!");
registerReceiver(discoveryReceiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED));
registerReceiver(discoveryReceiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
//----------扫描结果广播监听------------------------------------------------------------------------------
BroadcastReceiver discoveryResult = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("配对成功!");
String remoteDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME);
System.out.println(remoteDeviceName);
BluetoothDevice remoteD
remoteDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
System.out.println(remoteDevice);
foundDevice[DeviceNum] = remoteD
DeviceName[DeviceNum] = remoteDeviceN
DeviceNum++;
if(DeviceNum == 3) DeviceNum--;
//Toast.makeText(getApplicationContext(), "Discovered: "+remoteDeviceName, Toast.LENGTH_SHORT);
if(bAdapter.getBondedDevices().contains(remoteDevice)){
System.out.println("bond:"+remoteDeviceName);
adapter.notifyDataSetChanged();
registerReceiver(discoveryResult, new IntentFilter(BluetoothDevice.ACTION_FOUND));
if(!bAdapter.isDiscovering()){
bAdapter.startDiscovery();
for(int i = 0 ; i & DeviceName.i++){
DeviceName[i] = (String)(" ");
list = (ListView)this.findViewById(R.id.listview);
adapter = new ArrayAdapter&CharSequence&(this, android.R.layout.simple_list_item_1, DeviceName);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView&?& arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
ConnectBluetoothService(position);
//---------根据扫描结果进行绑定连接(作为从机)-------------------------------------------------------------------------
public void ConnectBluetoothService(int i){
System.out.println("I am here!");
System.out.println(foundDevice[i].getName());
System.out.println(uuid);
BluetoothSocket bs = foundDevice[i].createRfcommSocketToServiceRecord(uuid);
if(bAdapter.isDiscovering()){
bAdapter.cancelDiscovery();
bs.connect();
if(bs!=null)
System.out.println("Connect!");
//输出这个表示连接成功
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("蓝牙连接错误");
//--------------------------------------------------------------------------------------------------------
/* //--------------------监听绑定连接(作为主机)----------------------------------------------------------------------------------- @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode == DISCOVERY_REQUEST){
boolean isDiscoverable = requestCode & 0;
if(isDiscoverable){
String name = "bluetoothService";
final BluetoothServerSocket bServerSocket = bAdapter.listenUsingRfcommWithServiceRecord(name, uuid);
AsyncTask&Integer,Void,BluetoothSocket& accpetThread = new AsyncTask&Integer, Void, BluetoothSocket&(){
protected BluetoothSocket doInBackground(
Integer... params) {
// TODO Auto-generated method stub
bSocket = bServerSocket.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("蓝牙连接");
accpetThread.execute(resultCode);
new Thread(new Runnable(){
public void run() {
// TODO Auto-generated method stub
bSocket = bServerSocket.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("蓝牙连接错误");
}).start() ;
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("蓝牙主机搭建错误");
浏览: 14529 次
来自: 广州
dahuobao 写道我遇到一个问题,同一个型号的手机,同样的 ...
dahuobao 写道我遇到一个问题,同一个型号的手机,同样的 ...
我遇到一个问题,同一个型号的手机,同样的程序,获取http中文 ...
谢谢你的帮助 .
你的代码对我很有用我的蓝牙耳机连接不上手机,可能是因为我之前配对了一个,所以才连接不上的,请问要怎么才能在手机上面删除以前配对的那一个呢?
已有3个回答
[特聘专家]
专家星级&:&1.9星
问答堂专家综合评分
问题评分&:&2.2星
采纳、点赞&:&2星
二次回复率&:&0星
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
在蓝牙列表里,点击或长按那个蓝牙设备,然后选择删除设备,然后搜索,重新进行配对就可以了。
留下你的评论
专家星级&:&1.9星
问答堂专家综合评分
问题评分&:&2.3星
采纳、点赞&:&1.5星
二次回复率&:&2星
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
你好,长按以前配对的那个设备,选择删除就好了,然后在重新连接看看能否成功。
留下你的评论
内容为广告/垃圾,我要举报!
特聘专家具有协助内容审核的特权
举报后内容将不能在前台展示
错乱举报会导致该权利被剥夺
选择举报原因×
擅长领域:
参与话题:
& & &楼主你好,楼主找到这个蓝牙设备之后,长按然后选择删除就可以了。
留下你的评论
微信公众账号ZOL问答堂
关注微信,随时随地解答您的疑惑
ZOL问答堂官方微博@ZOL问答堂
关注成功!该问题被回答后,将给您发送站内短信。
您也可以通过关注问答堂微信,及时获得您关注问题的回答。
微信关注问题方法“”您的举报已经提交成功,我们将尽快处理,谢谢!
在蓝牙设置里配对就可以。。。
一般来说 都是一格步骤 先打开手机蓝牙,然后按住蓝牙耳机的电源(有的时候是接听或者播放)键不动,3秒左右开机,然后别松手继续按,就会发现他的灯一闪一闪的,这时候...
点设置,左边向下滑,如果是国行,就可以找到,如果是美版的,就可以慢慢查了
大家还关注}

我要回帖

更多关于 蓝牙配对成功无法连接 的文章

更多推荐

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

点击添加站长微信