佩戴OS 3 / API 30,交互式表盘水龙头不显示吐司



如果您使用最新的稳定Android studio为API 30创建一个交互式Android表盘(我使用java)并在API 30 Wear OS模拟器上运行它,则tap处理程序无法显示其toast。在API28模拟器上一切正常。

见这里https://issuetracker.google.com/issues/265982091

有真正的API 30手表的人可以帮我试一下交互式表盘吗?我不清楚这个bug是在API 30模拟器还是在Wear OS3本身。

显示额外的信息从表盘或复杂的点击使用一个简单的(非自定义)Toast似乎是一个非常合理的事情想要做。

我在Kotlin API 30或31中没有遇到任何问题。

你可以在这里查看我的完整代码作为示例:

https://github.com/SarahBass/HoroscopeWatchAndroid/blob/main/MyWatchFace.kt

它通过祝酒词告诉用户星星、月亮和日历数据。当你导入字符串时,它也能很好地工作。

下面是我的一些代码片段。很抱歉我写得很潦草——我是用手机发这条短信的,效果不像我希望的那么好。下面是一个快速复制粘贴的例子:

import android.widget.Toast
import java.lang.ref.WeakReference
import java.text.SimpleDateFormat
import java.util.*
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
override fun onTapCommand(tapType: 
Int, x: Int, y: Int, eventTime: 
Long) {
//Shows different methods to 
call strings
when (tapType) {
TAP_TYPE_TOUCH -> {
// The user has 
started touching the screen.
}
TAP_TYPE_TOUCH_CANCEL -> 
{
// The user has 
started a different gesture or 
otherwise cancelled the tap.
}
TAP_TYPE_TAP -> {
getToast()}

else->{}

invalidate()
}
private fun getToast() {
val frameTime = 
INTERACTIVE_UPDATE_RATE_MS
val sdf =  SimpleDateFormat("EEE")
val sdf1 = SimpleDateFormat("EEEE")
val sdf2 = SimpleDateFormat("MMMM")
val sdf3 = SimpleDateFormat("d")
val sdf4 = SimpleDateFormat("yyyy")
val sdf5 = SimpleDateFormat("MMMM d yyyy")
val sdf6 = SimpleDateFormat("h:mm:ss a")
val sdf7 = SimpleDateFormat("a")
val d = Date()
val dayOfTheWeek: String = sdf.format(d)
val dayOfTheWeekLong: String = sdf1.format(d)
val monthOfYear: String = sdf2.format(d)
val dayOfMonth: String =sdf3.format(d)
val year4digits: String = sdf4.format(d)
val fullDateSpaces: String = sdf5.format(d)
val timeSpecific : String = sdf6.format(d)
val amPM : String = sdf7.format(d)
Toast.makeText(

applicationContext,
"$dayOfTheWeek , 
$fullDateSpaces",

Toast.LENGTH_SHORT
)}}

您是否在api30wear OS模拟器上运行您的代码?如果没有,我会从你的github上试试。