android - DeviceClient 调用方法打开时出错
问题描述
我正在使用此页面上的 Android 示例代码。
刚刚将第29 行的connstring"Hostname=<myHostname>.azureiotcentral.com;DeviceId=<myDevice>;SharedAccessKey=<myPrimaryKey>"
的内容替换为;
我正在使用 SAS 身份验证。
第一个错误是它尝试调用时client.open()
(第 138 行)。
每次尝试发送消息时都会给我以下错误(第 122 行)。
Connected to process 20170 on device '7.3_Foldable_API_30 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
No Network Security Config specified, using platform default
I/MultiDex: VM with version 2.1.0 has multidex support
Installing application
VM has multidex support, MultiDex support library is disabled.
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
I/TetheringManager: registerTetheringEventCallback:com.example.kttracking
W/System.err: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
D/HostConnection: HostConnection::get() New Host Connection established 0xf03da8e0, tid 20194
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0
W/System.err: Exception while opening IoTHub connection: java.io.IOException: Could not open the connection
I/System.out: Shutting down...
I/System.out: Message Sent: "temperature":22.84, "humidity":48.31
W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed.
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/EGL_emulation: eglCreateContext: 0xf03f3ee0: maj 3 min 0 rcv 3
D/EGL_emulation: eglMakeCurrent: 0xf03f3ee0: ver 3 0 (tinfo 0xf0738cf0) (first time)
I/Gralloc4: mapper 4.x is not supported
D/HostConnection: createUnique: call
HostConnection::get() New Host Connection established 0xf03f3af0, tid 20194
D/goldfish-address-space: allocate: Ask for block of size 0x100
allocate: ioctl allocate returned offset 0x3fc01c000 size 0x2000
D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_3_0
I/System.out: Message Sent: "temperature":20.74, "humidity":31.12
W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed.
I/System.out: Message Sent: "temperature":26.08, "humidity":43.27
W/System.err: Exception while sending event: java.lang.IllegalStateException: Cannot send event from an IoT Hub client that is closed.
解决方案
你使用什么协议?那是MQTT吗?另外请检查您使用的设备客户端的版本。
您可以做的第二件事是在不同的设备上尝试,看看问题是否仍然存在。有时某些设备确实会出现这样的问题。
推荐阅读
- python - Python 代码在函数和类之外工作,但不在内部
- java - Eclipse 中的端口已在使用中出现 8080 错误提示,但在运行时它在 Web 浏览器中的端口 8080 上工作
- sql-server - SQL Server 参数化查询不使用非聚集筛选
- r - 将主要网格线对齐到条形宽度的末端而不是切入条形?
- android - 为什么我不能使用 KivyMD 为 android 构建 apk?
- java - Java Random.nextInt() 行为
- racket - Racket(递归结构和处理模板)
- c - 如何从一个函数访问文件指针到另一个函数?
- assembly - 在程序集 irvine 32 中从 16 位转换为 32 位
- android - 无法在 recyclerView 上显示数据