关于ACTION_LOCAL_NAME_CHANGED使用时的注意事项

先附上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;
  }
}

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值