断开连接后,Android BLE在后台连接

时间:2017-06-19 22:28:55

标签: android bluetooth-lowenergy rxandroidble

我们正在使用RxAndroidBle 1.3.1连接到Android的BLE设备。在某些手机上(目前我在LG V20 [LG-H918],Android 7.0上看到这一点),在我们的应用程序断开连接后,手机将继续连接而无需任何用户输入。

当我们关闭我们的应用时,设备会断开连接。然后我们就可以杀死我们的app流程大约20秒左右,手机重新连接到设备约2秒钟然后断开连接。此行为会无限期地每10-20秒重复一次,直到我们重新启动手机。

实际上,如果我们在连接仍然存在时硬杀死应用程序,我们甚至会获得重复连接。

这些是我们断开连接时的日志:

public partial class MyService : ServiceBase
{
    private void SchedulerCallback()
    {
        using (var myContext = new MyContext())
        {
            var UserManager = new ApplicationUserManager(new UserStore<ApplicationUser>(MyContext));

            var users = (from u in myContext.Users where u.Status = StatusFlag.PlaceOrder select u.User).ToList();

            foreach (var user in users)
            {
                myContext.Order.Add(new MyOrder());
                myContext.Order.User = user;

                OrderTransaction transaction = new OrderTransaction();
                order.Transactions = new List<OrderTransaction>();
                order.Transactions.Add(transaction);

                user.Status = StatusFlag.OrderPlaced;
            }

            try
            {
                myContext.SaveChanges();
            }
            catch (Exception e)
            {
                Logger.LogError("Exception", e);
            }
        }
    }   
} 

我很困惑;任何帮助表示赞赏!

3 个答案:

答案 0 :(得分:0)

确保当您从应用中连接Gatt配置文件时,您已将自动连接标记设置为SaveMoneyBolt来自Android documentation以获取BLE: -

  

连接到GATT服务器与BLE交互的第一步   设备正在连接到它 - 更具体地说,是连接到GATT   设备上的服务器。要连接到BLE设备上的GATT服务器,   使用connectGatt()方法。该方法有三个参数:a   Context对象,autoConnect(boolean指示是否为   它一旦自动连接到BLE设备   可用),以及对BluetoothGattCallback的引用:

     

false

答案 1 :(得分:0)

确保您调用close方法。

close method

答案 2 :(得分:0)

罪魁祸首是Spotify Connect。它会监视任何断开连接的蓝牙设备,并立即尝试连接它。有时它会进入无限循环,有时连接循环最终会停止。但是我们能够通过停止SC来摆脱这种破坏性的行为,我们能够通过安装它来在其他手机上实现它。

另见Android BLE unexpectedly and repeatedly reconnects to peripheral