纽轱辘小铭 2023-03-28 12:09 采纳率: 88.9%
浏览 16
已结题

E/BluetoothGatt:android.os.DeadObjectException

Android 当我连接成功之后,关闭蓝牙再打开蓝牙就出现这种情况。可能是蓝牙重新打开后,服务还未绑定完成,就去调用connect连接,导致的。某个对象已经不存在引起的异常。


E/BluetoothGatt: android.os.DeadObjectException
        at android.os.BinderProxy.transactNative(Native Method)
        at android.os.BinderProxy.transact(BinderProxy.java:532)
        at android.bluetooth.IBluetoothGatt$Stub$Proxy.registerForNotification(IBluetoothGatt.java:2276)

img

网上的方法:在application标签里面添加一句android:hardwareAccelerated="false"(禁用硬件加速)对我来说没有用,应该怎么解决呢?

  • 写回答

1条回答 默认 最新

  • Leodong. 2023-03-28 12:28
    关注

    该回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
    这个问题可能是因为你的应用程序没有正确地断开与蓝牙设备的连接导致的。尝试在你的代码中添加正确的断开连接代码,以确保在重新打开蓝牙之前已经断开了蓝牙连接。

    另外,如果你使用的是Android 6.0或更高版本,则需要在运行时请求蓝牙权限。确保你的应用程序已经正确地请求了必要的权限。你可以使用以下代码请求蓝牙权限:

    private static final int REQUEST_ENABLE_BT = 1;
    private static final int REQUEST_PERMISSION_COARSE_LOCATION = 1;
    
    // ...
    
    BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    
    // Ensures Bluetooth is available on the device and it is enabled. If not,
    // displays a dialog requesting user permission to enable Bluetooth.
    if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
    
    // Requests permission to access the device's location. Required for scanning
    // for Bluetooth devices on Android 6.0 and above.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                REQUEST_PERMISSION_COARSE_LOCATION);
    }
    

    如果这些方法不起作用,你可以尝试在蓝牙连接之前添加一个延迟来确保服务已经绑定完成。例如,使用以下代码将连接延迟3秒:

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            // Connect to Bluetooth device
        }
    }, 3000);
    

    最后,你也可以尝试更新你的Android操作系统和蓝牙驱动程序,以确保它们是最新版本,可能会解决一些与蓝牙连接相关的问题。


    如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月6日
  • 已采纳回答 3月29日
  • 创建了问题 3月28日

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景