Reputation: 121
If you use the latest stable Android studio to create an interactive androidx watch face for API 30 (I used java) and run it on the API 30 Wear OS emulator, the tap handler fails to display its toast. All is good on the API28 emulator.
See here https://issuetracker.google.com/issues/265982091
Might someone with a real API 30 watch try out the interactive watch face for me please. Its not clear to me whether the bug is in the API 30 Emulator or Wear OS3 itself.
Showing extra info from a watch face or complication tap using a simple (non custom) Toast seems a very reasonable thing to want to do.
Upvotes: 0
Views: 256
Reputation: 1
Have you run your code on the API30 Wear OS emulator? If not, I will give it a go from your github.
Upvotes: 0
Reputation: 26
I haven't had any problems with toast in Kotlin in API 30 or 31.
You can check out my full code here as an example:
https://github.com/SarahBass/HoroscopeWatchAndroid/blob/main/MyWatchFace.kt
It tells the user star , moon, and calendar data through toasts. It works well when you import strings too.
Here's a few of my code snippets. Sorry for the sloppiness- I'm texting this from my phone and it is not working as well as hoped. Here is a quick copy paste example :
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
)}}
Upvotes: 0