in RuntimePermissionsWear/Application/src/main/java/com/example/android/wearable/runtimepermissions/MainPhoneActivity.kt [181:218]
override fun onResume() {
Log.d(TAG, "onResume()")
super.onResume()
if (ActivityCompat.checkSelfPermission(this, phoneSummaryPermission)
== PackageManager.PERMISSION_GRANTED
) {
binding.phoneInfoPermissionButton.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.ic_very_satisfied, 0, 0, 0
)
}
// Clients are inexpensive to create, so in this case we aren't creating member variables.
// (They are cached and shared between GoogleApi instances.)
Wearable.getMessageClient(this).addListener(this)
Wearable.getCapabilityClient(this).addListener(
this, Constants.CAPABILITY_WEAR_APP
)
// Initial check of capabilities to find the phone.
lifecycleScope.launch {
try {
val capabilityInfo = Wearable.getCapabilityClient(this@MainPhoneActivity)
.getCapability(Constants.CAPABILITY_WEAR_APP, CapabilityClient.FILTER_REACHABLE)
.await()
if (capabilityInfo.name == Constants.CAPABILITY_WEAR_APP) {
wearNodeIdsState.value = capabilityInfo.nodes
}
Log.d(TAG, "Capability request succeeded.")
} catch (cancellationException: CancellationException) {
throw cancellationException
} catch (throwable: Throwable) {
Log.d(TAG, "Capability request failed to return any results.")
}
}
}