feat: added companion app for WearOS, and setted up icons
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package ru.omni_devel.cards
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.widget.Toast
|
||||
import com.google.android.gms.wearable.Wearable
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.MultiFormatWriter
|
||||
import com.journeyapps.barcodescanner.BarcodeEncoder
|
||||
@@ -11,3 +14,29 @@ fun generateCode(value: String, format: BarcodeFormat): Bitmap {
|
||||
|
||||
return BarcodeEncoder().createBitmap(matrix)
|
||||
}
|
||||
|
||||
fun sendToWatch(context: Context, path: String, message: String): Boolean {
|
||||
val nodeClient = Wearable.getNodeClient(context)
|
||||
|
||||
var isSuccess = false
|
||||
|
||||
nodeClient.connectedNodes.addOnSuccessListener { nodes ->
|
||||
if (nodes.isEmpty()) {
|
||||
Toast.makeText(context, "Watch is not connected", Toast.LENGTH_SHORT).show()
|
||||
|
||||
return@addOnSuccessListener
|
||||
}
|
||||
|
||||
nodes.forEach { node ->
|
||||
Wearable.getMessageClient(context).sendMessage(
|
||||
node.id,
|
||||
path,
|
||||
message.toByteArray(Charsets.UTF_8)
|
||||
).addOnSuccessListener {
|
||||
isSuccess = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isSuccess
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user