【发布时间】:2021-05-16 09:42:42
【问题描述】:
有没有办法调试被调用的方法?
我正在调用这个方法,但没有抛出任何错误。
Class Reference:
方法:public boolean disconnect(BluetoothDevice device)
发送的结果是false。出于这个原因,这些行中的任何一个都必须已执行并分配了布尔值。我希望service.disconnect(device) 被调用并返回false,但我想证明这一点。
try {
[...]
if (service != null && isEnabled() && isValidDevice(device)) {
return service.disconnect(device);
}
if (service == null) Log.w(TAG, "Proxy not attached to service");
return false;
} catch (RemoteException e) {
Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
return false;
}
BluetoothA2dp.disconnect() 被这段代码调用
private fun disconnect(context: Context, device: BluetoothDevice) {
val serviceListener: ServiceListener = object : ServiceListener {
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
try {
val disconnectMethod = BluetoothA2dp::class.java.getDeclaredMethod("disconnect", BluetoothDevice::class.java)
disconnectMethod.isAccessible = true
val cReturn = disconnectMethod.invoke(proxy, device) as Boolean
} catch (ex: Throwable) {
error("disconnectMethod", ex)
} finally {
bluetoothAdapter!!.closeProfileProxy(profile, proxy)
}
}
override fun onServiceDisconnected(profile: Int) {}
}
bluetoothAdapter!!.getProfileProxy(context, serviceListener, BluetoothProfile.A2DP)
}
法布里奇奥的方式:
遗憾的是,叠加层被隐藏了,但我点击了step in
【问题讨论】:
标签: java android android-studio kotlin