小编Bon*_*i2k的帖子

Android BLE API:未收到GATT通知

用于测试的设备:Nexus 4,Android 4.3

连接工作正常,但onCharacteristicChanged我的回调方法永远不会被调用.但是我正在使用setCharacteristicNotification(char, true)inside 注册通知onServicesDiscovered,该函数甚至返回true.

设备日志(当通知应该出现/通过蓝牙设备发送时,实际上根本没有消息):

07-28 18:15:06.936  16777-16809/de.ffuf.leica.sketch D/BluetoothGatt: setCharacteristicNotification() - uuid: 3ab10101-f831-4395-b29d-570977d5bf94 enable: true
07-28 18:15:06.936    4372-7645/com.android.bluetooth D/BtGatt.GattService: registerForNotification() - address=C9:79:25:34:19:6C enable: true
07-28 18:15:06.936    4372-7645/com.android.bluetooth D/BtGatt.btif: btif_gattc_reg_for_notification
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, charUuid=3ab10101-f831-4395-b29d-570977d5bf94
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1016
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946    4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth bluetooth-lowenergy gatt android-4.3-jelly-bean

68
推荐指数
5
解决办法
7万
查看次数

执行AsyncTask时替换碎片 - getActivity()上的NullPointerException

我最近将我的活动转换为碎片.

使用与Tab-Navigation类似的东西,当用户选择另一个选项卡时,将替换片段.填充片段后,我启动至少一个AsyncTask以从Internet获取一些信息.但是 - 如果用户切换到另一个选项卡,就像我的AsyncTask中的doBackground方法正在执行一样 - 片段被替换,因此我得到一个NullPointerException标记的行:

@Override
protected Object doInBackground(Object... params) {
  ...
  String tempjson = helper.SendPost(getResources().getText(R.string.apiid)); //ERROR: Fragment not attached
  ...
}

protected onPostExecute(Object result) {
  ...
  getActivity().getContentResolver() //NULLPOINTEREXCEPTION
  getView().findViewById(R.id.button) //NULL
  ...
}
Run Code Online (Sandbox Code Playgroud)

getActivity()并且getResources()因为我的Fragment被替换而导致错误.

我试过的事情:

  • 在我的AsyncTask上调用cancel方法(如果在onPostExecute()执行时替换片段,则不会修复第一个错误,也不会修复第二个错误)
  • 检查是否getActivity()正在null调用this.isDetached()(不是真正的修复,我需要在每次呼叫时检查它getActivity()等等)

所以我的问题是:什么是最好摆脱这些AsyncTask问题?我没有使用活动这些问题,因为它们没有在标签更改时"被杀死"/分离(导致更高的内存使用量 - 我之所以想切换到碎片)

android android-asynctask android-fragments

20
推荐指数
1
解决办法
7061
查看次数

XCode:运行未连接调试器的iOS应用程序

我目前正在尝试在没有附加调试器的情况下在iOS设备上测试我的应用程序.这是为了测试PLCrashReporter库,因为调试器会捕获所有崩溃而不是CrashReporter.

我试过的事情:

  • 在发布模式下运行
  • 禁用断点

必须有一种方法来实现这一点,而无需导出IPA文件并手动安装.我想看看NSLog消息,我不能使用IPA文件.

非常感谢帮助!

debugging xcode ios

2
推荐指数
1
解决办法
1537
查看次数