您的位置:首页 > 其它

关于ACTION_LOCAL_NAME_CHANGED使用时的注意事项

2016-12-07 21:15 351 查看
  先附上SDK中关ACTION_LOCAL_NAME_CHANGED的说明:

Broadcast Action: The local Bluetooth adapter has changed its friendly Bluetooth name.

This name is visible to remote Bluetooth devices.

Always contains the extra field
EXTRA_LOCAL_NAME
containing the name.

Requires
BLUETOOTH
to receive.

Constant Value:
"android.bluetooth.adapter.action.LOCAL_NAME_CHANGED"

  最近开发蓝牙相关APP的时候发现了一个现象:启动蓝牙时候系统也会发布ACTION_LOCAL_NAME_CHANGED这个广播,而此时并没有使用APP中的重命名蓝牙适配器的功能。这就可能会给自身APP中的广播接收器带来一些误操作,因此需要在进行相关操作前进行一个判断操作,广播接收部分代码段如下:

public void onReceive(Context c, Intent i)
{
switch (i.getAction())
{
case BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED:
{
//必须先进行此层if判断避免启动时的误判断
if(mBluetoothStateManager.BluetoothStateManger_getBluetoothAdapter().isEnabled())
{
System.out.println("Name has changed!\n");//可替换成你想要的响应操作
}
}break;
default:break;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: