Google uses AI technology to translate content into your preferred language. AI translations can contain errors.
Hub Activation API ใน Android
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
HubManagementTrait
เมื่อใช้ Hub Activation API คุณจะสร้างแอปที่ค้นพบและเปิดใช้งานฮับได้ โดยทำดังนี้
รับข้อมูลอ้างอิงถึง
HubManagementTraitใน
โครงสร้าง
val hubManagementTrait =
hubManagementTraitFlow.firstOrNull {
it.metadata.sourceConnectivity?.connectivityState == ConnectivityState.ONLINE
}
if (hubManagementTrait == null) {
errorsEmitter.emit(HomeException.notFound("HubManagement trait isn't online"))
}
ระบุอุปกรณ์ที่ใช้ฮับได้ในเครือข่าย Wi-Fi
try {
val unused = hubManagementTrait.discoverAvailableHubs()
} catch (e: Exception) {
Log.d(TAG_HUB_DISCOVERY, "Error discovering hubs $e")
errorsEmitter.emit(e)
}
val hubManagementTraitFlow = structureFlow.flatMapLatest { it.trait(HubManagement) }
val discoveredHubs =
hubManagementTraitFlow
.map { it.discoveredHubsList }
.handleErrors()
.flowOn(ioDispatcher)
.stateIn(
scope = CoroutineScope(viewModelScope.coroutineContext + ioDispatcher),
started = SharingStarted.WhileSubscribed(),
listOf(),
)
เปิดใช้งานอุปกรณ์ที่ใช้ฮับได้
try {
val unused = hubManagementTrait.activateHub(hub)
} catch (e: Exception) {
Log.d("Hub Activation", "Error activating hub $e")
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-12-09 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ข้อมูลไม่ถูกต้อง","incorrectInformation","thumb-down"],["ข้อมูล/ตัวอย่างไม่เพียงพอ","notEnoughInformationSamples","thumb-down"],["ซับซ้อนเกินไป","tooComplicated","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-12-09 UTC"],[],[]]