android蓝牙配对
Ⅰ 安卓蓝牙耳机怎么配对
具体步骤:
1.我们在外出之前要记得给自己的蓝牙耳机充满电,以保证中途不会突然断电,像诺基亚BH-503蓝牙耳机,充满一次电就能使用十个小时以上,这对于经常出 门 的人来说是很不错的性能,并且诺基亚BH-503采用的是头戴式不容易掉落。
2.充满电之后,我们就可以开始进行连接配对了,首先我们先打开手机的蓝牙功能,一般的手机蓝牙选项在设置选项里面,设置选项菜单一打开基本就能看见了,不会太难找。一般的安卓智能手机还要在蓝牙选项里面在设置“可以被设备检测到”选项,让自己的蓝牙能够检测到自己的手机,诺基亚830就没有这一繁琐的步骤。
3.打开手机蓝牙后,我们还要打开蓝牙耳机,诺基亚BH-503的 开关 机方式是长按多功能件直至 指示灯 一直闪烁蓝光,这样就开机了并且能被连接(主要在闪烁绿光的时候不要松手,因为这样只是开机并不能被手机连接到)关机和开机差不多,长按多功能键,直至红光出现就算是关机了。
4.两个设备都打开蓝牙功能之后,我们就可以进行连接配对了。一般蓝牙功能都是在10左右才有效,所以不要距离太远。如果配对还提示需要配对密码的话,我们的蓝牙默认配对密码基本上都是四个零,输入密码点击配对,就可以进行配对了。如果连接不上,我们可以重新启动蓝牙,在进行重新配对。配对成功之后,蓝牙耳机会滴的一声以用来提示连接成功。这时诺基亚BH-503的指示灯就会以蓝色的光芒进行缓慢闪烁,这就算连接成功了。
Ⅱ syu android蓝牙连接方法
syu android蓝牙连接方法先展示代码结构。
蓝牙是一种无线数据与语音通信的开放性全球规范,它以低成本的短距离无线连接为基础,可为固定的或移动的终端设备提供廉价的接入服务。
蓝牙(Bluetooth)是一项短途无线电连接系统,它可以将不同的电子器材连系起来。原理就好像收音机一样,装有蓝牙的电子器材,可以接收外来的讯息,从而进行特定的指令。
蓝牙简介:
不过,蓝牙不但可以接收,也都可以“传送”,因此装有蓝牙的电子器材,能够互相沟通。现在,大部分的电脑配件,如打印机、荧幕等,都要接驳上电线,才可以互传讯息,但蓝牙透过其短途的接收系统,便可以使这些配件在没有驳线下,仍然能够传送指令,做到真正“无线”的世界。
头蓝技术实质内容是为固定设备或移动设备之间的通信环境建立通用的近距无线接口,将通信技术与计算机技术进一步结合起来,使各种设备在没有电线或电缆相互连接的情况下,能在近距离范围内实现相互通信或操作。蓝牙功能可以参考下面的操作打开使用,打开其他设备的蓝牙。
并使其对其他设备可见,打开下拉顶帘,点击蓝牙图标使其变为绿色,跳出提示框,勾选对其他设备可见。点击扫描,搜索到其他设备后,点击该设备名称,双方点确定后配对成功。选择要传输的文件,共享通过蓝牙即可传输文件。
Ⅲ android 手机蓝牙怎样自动连接已配对的设备
蓝牙和手机的详细连接步骤如下:
1,手机打开蓝牙功能,进去搜索蓝牙耳机状态。
2,使蓝牙耳机在开机状态,需要长按蓝牙耳机的接听键。
3,直到指示灯:蓝灯红灯交替闪烁再松开。
4,这个时候蓝牙耳机和手机会再次进入匹对。
5,注意手机和蓝牙距离要在10米内。
等手机上面显示此蓝牙型号设备后,点击确定即可连接使用了。
Ⅳ android蓝牙配对 如何自动配对设置PIN码
Android对于音频设备是自动输入0000的pin码的,参照$frameworks/base/core/java/android/server/BluetoothEventLoop.java 的onRequestPinCode()你若是在app里编写代码,可以在收到ACTION_PAIRING_REQUEST的时候,直接调用BluetoothDevice.setpin()reference $package/apps/Settings/src/android/settings/bluetooth/BluetoothPairingDialog.java 的onPair();
Ⅳ Android中如何实现蓝牙的配对与连接
蓝牙功能可以参考下面的操作打开使用:
1.打开其他设备的蓝牙,并使其对其他设备可见。
2.打开下拉顶帘,点击蓝牙图标使其变为绿色,跳出提示框,勾选对其他设备可见。
3.点击扫描,搜索到其他设备后,点击该设备名称,双方点确定后配对成功。
4.选择要传输的文件,共享通过蓝牙即可传输文件。
Ⅵ android 怎么判断蓝牙配对成功
可以通过mDevice.getBondState()进行判断是否需要配对;
如下代码中: (mBluetoothDevice.getBondState()==BluetoothDevice.BOND_NONE表示未配对。可以在调用配对方法之后读取一下这个状态来判断是否已配对成功。)
protectedvoidconnectDevice(){
try{
//连接建立之前的先配对
if(mBluetoothDevice.getBondState()==BluetoothDevice.BOND_NONE){
MethodcreMethod=BluetoothDevice.class
.getMethod("createBond");
Log.e("TAG","开始配对");
creMethod.invoke(mBluetoothDevice);
}else{
}
}catch(Exceptione){
//TODO:handleexception
//DisplayMessage("无法配对!");
e.printStackTrace();
}
mBluetoothAdapter.cancelDiscovery();
try{
socket.connect();
//DisplayMessage("连接成功!");
//connetTime++;
connected=true;
}catch(IOExceptione){
//TODO:handleexception
//DisplayMessage("连接失败!");
connetTime++;
connected=false;
try{
socket.close();
socket=null;
}catch(IOExceptione2){
//TODO:handleexception
Log.e(TAG,"");
}
}finally{
connecting=false;
}
}
Ⅶ 如何实现android蓝牙开发 自动配对连接,并不弹出提示框
我就开始查找怎么关闭这个蓝牙配对提示框,后面还是伟大的android源码帮助了我。
在源码 BluetoothDevice 类中还有两个隐藏方法
cancelBondProcess()和cancelPairingUserInput()
这两个方法一个是取消配对进程一个是取消用户输入
下面是自动配对的代码
Mainfest,xml注册
<receiverandroid:name=".">
<intent-filter>
<actionandroid:name="android.bluetooth.device.action.PAIRING_REQUEST"/>
</intent-filter>
</receiver>
自己在收到广播时处理并将预先输入的密码设置进去
{
StringstrPsw="0";
@Override
publicvoidonReceive(Contextcontext,Intentintent)
{
//TODOAuto-generatedmethodstub
if(intent.getAction().equals(
"android.bluetooth.device.action.PAIRING_REQUEST"))
{
BluetoothDevicebtDevice=intent
.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
//byte[]pinBytes=BluetoothDevice.convertPinToBytes("1234");
//device.setPin(pinBytes);
Log.i("tag11111","ddd");
try
{
ClsUtils.setPin(btDevice.getClass(),btDevice,strPsw);//手机和蓝牙采集器配对
ClsUtils.createBond(btDevice.getClass(),btDevice);
ClsUtils.cancelPairingUserInput(btDevice.getClass(),btDevice);
}
catch(Exceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
}
<b>/************************************蓝牙配对函数***************/
importjava.lang.reflect.Field;
importjava.lang.reflect.Method;
importandroid.bluetooth.BluetoothDevice;
importandroid.util.Log;
publicclassClsUtils
{
/**
*与设备配对参考源码:platform/packages/apps/Settings.git
*/Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
staticpublicbooleancreateBond(ClassbtClass,BluetoothDevicebtDevice)
throwsException
{
MethodcreateBondMethod=btClass.getMethod("createBond");
BooleanreturnValue=(Boolean)createBondMethod.invoke(btDevice);
returnreturnValue.booleanValue();
}
/**
*与设备解除配对参考源码:platform/packages/apps/Settings.git
*/Settings/src/com/android/settings/bluetooth/CachedBluetoothDevice.java
*/
staticpublicbooleanremoveBond(ClassbtClass,BluetoothDevicebtDevice)
throwsException
{
MethodremoveBondMethod=btClass.getMethod("removeBond");
BooleanreturnValue=(Boolean)removeBondMethod.invoke(btDevice);
returnreturnValue.booleanValue();
}
staticpublicbooleansetPin(ClassbtClass,BluetoothDevicebtDevice,
Stringstr)throwsException
{
try
{
MethodremoveBondMethod=btClass.getDeclaredMethod("setPin",
newClass[]
{byte[].class});
BooleanreturnValue=(Boolean)removeBondMethod.invoke(btDevice,
newObject[]
{str.getBytes()});
Log.e("returnValue",""+returnValue);
}
catch(SecurityExceptione)
{
//thrownewRuntimeException(e.getMessage());
e.printStackTrace();
}
catch(IllegalArgumentExceptione)
{
//thrownewRuntimeException(e.getMessage());
e.printStackTrace();
}
catch(Exceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
returntrue;
}
//取消用户输入
(ClassbtClass,
BluetoothDevicedevice)
throwsException
{
MethodcreateBondMethod=btClass.getMethod("cancelPairingUserInput");
//cancelBondProcess()
BooleanreturnValue=(Boolean)createBondMethod.invoke(device);
returnreturnValue.booleanValue();
}
//取消配对
(ClassbtClass,
BluetoothDevicedevice)
throwsException
{
MethodcreateBondMethod=btClass.getMethod("cancelBondProcess");
BooleanreturnValue=(Boolean)createBondMethod.invoke(device);
returnreturnValue.booleanValue();
}
/**
*
*@paramclsShow
*/
(ClassclsShow)
{
try
{
//取得所有方法
Method[]hideMethod=clsShow.getMethods();
inti=0;
for(;i<hideMethod.length;i++)
{
Log.e("methodname",hideMethod[i].getName()+";andtheiis:"
+i);
}
//取得所有常量
Field[]allFields=clsShow.getFields();
for(i=0;i<allFields.length;i++)
{
Log.e("Fieldname",allFields[i].getName());
}
}
catch(SecurityExceptione)
{
//thrownewRuntimeException(e.getMessage());
e.printStackTrace();
}
catch(IllegalArgumentExceptione)
{
//thrownewRuntimeException(e.getMessage());
e.printStackTrace();
}
catch(Exceptione)
{
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}</b>
执行时直接使用:
<b>publicstaticbooleanpair(StringstrAddr,StringstrPsw)
{
booleanresult=false;
=BluetoothAdapter
.getDefaultAdapter();
bluetoothAdapter.cancelDiscovery();
if(!bluetoothAdapter.isEnabled())
{
bluetoothAdapter.enable();
}
if(!BluetoothAdapter.checkBluetoothAddress(strAddr))
{//检查蓝牙地址是否有效
Log.d("mylog","devAdneffient!");
}
BluetoothDevicedevice=bluetoothAdapter.getRemoteDevice(strAddr);
if(device.getBondState()!=BluetoothDevice.BOND_BONDED)
{
try
{
Log.d("mylog","NOTBOND_BONDED");
ClsUtils.setPin(device.getClass(),device,strPsw);//手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(),device);
remoteDevice=device;//配对完毕就把这个设备对象传给全局的remoteDevice
result=true;
}
catch(Exceptione)
{
//TODOAuto-generatedcatchblock
Log.d("mylog","setPiNfailed!");
e.printStackTrace();
}//
}
else
{
Log.d("mylog","HASBOND_BONDED");
try
{
ClsUtils.createBond(device.getClass(),device);
ClsUtils.setPin(device.getClass(),device,strPsw);//手机和蓝牙采集器配对
ClsUtils.createBond(device.getClass(),device);
remoteDevice=device;//如果绑定成功,就直接把这个设备对象传给全局的remoteDevice
result=true;
}
catch(Exceptione)
{
//TODOAuto-generatedcatchblock
Log.d("mylog","setPiNfailed!");
e.printStackTrace();
}
}
returnresult;
}</b>
Ⅷ 安卓手机系统怎么蓝牙配对
设置--无线和网络--蓝牙
选中那个框就可以了
Ⅸ 如何实现android蓝牙自动配对连接
android蓝牙自动配对连接的具体代码如下:
1. 获取蓝牙适配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 为null,说明android手机没有蓝牙模块。
2. 判断蓝牙模块是否开启,blueadapter.isEnabled() true表示已经开启,false表示蓝牙并没启用。
3. 启动配置蓝牙可见模式,即进入可配对模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
4. 获取蓝牙适配器中已经配对的设备Set<BluetoothDevice> device=blueadapter.getBondedDevices();
当然,还需要在androidManifest.xml中声明蓝牙的权限
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5.自动配对设置Pin值
static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin)
throws Exception {
Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class });
Boolean result = (Boolean) autoBondMethod
.invoke(device, new Object[] { strPin.getBytes() });
return result;
}
6.开始配对请求
static public boolean createBond(Class btClass, BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}
Ⅹ android蓝牙怎么控制手机
机连接不上蓝牙耳机有以下几个解决办法:一、蓝牙耳机没有进入配对模式;解决方法:每一款蓝牙耳机都有一个功能按键,长按多功能按键直至红蓝灯交替闪动后松手,打开手机蓝牙进行搜索 配对即可连接解决方法:同时按住 多 功能按键和音量控制+键 大约4秒 红灯闪动一下,表示清除所有配对记录,然后再长按多 功能 按键直至红蓝灯交替闪动后,打开手机蓝牙配 对连接即可三、手机蓝牙与 耳机蓝牙版本不兼容。这个无法解决,建议 找耳机卖家进行退换货。