最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Kotlin umpaired device "removeBond" not found - Stack Overflow

programmeradmin0浏览0评论

I m building an Android application usign Kotlin, with this application I manage bluetooth device. Now I need to umpaired Bluetooth device programmatically. So I build the following code:

pairedDevices = mBluetoothAdapter?.bondedDevices;
                    if (pairedDevices?.size!! > 0) {
                        for (device in pairedDevices!!) {
                            if(device.address.equals(d.macAddress)){
                                try {

                                    val m: Method = device.javaClass
                                        .getMethod("removeBond", null)
                                    m.invoke(device, null as Array<Any?>?)
                                } catch (e: Exception) {
                                    e.message?.let { Log.e("Removing has been failed.", it) }
                                }
                            }

                        }
                    }

But if I try to execute this code:

val m: Method = device.javaClass
.getMethod("removeBond", null)

I received the following error:

java.lang.NoSuchMethodException: parameter type is null

How can I fixed it?

发布评论

评论列表(0)

  1. 暂无评论