1
+ package com.example.validator
2
+
3
+ import com.google.android.wearable.watchface.validator.client.DwfValidatorFactory
4
+ import java.io.File
5
+ import java.io.FileOutputStream
6
+ import kotlin.system.exitProcess
7
+
8
+ class Main {
9
+ companion object {
10
+ @JvmStatic
11
+ fun main (args : Array <String >) {
12
+ println (" Watch Face Push validator test program" )
13
+ performValidation()
14
+ }
15
+ }
16
+ }
17
+
18
+ private fun performValidation () {
19
+ val watchFaceFile = obtainTempWatchFaceFile()
20
+ val appPackageName = " com.example.validator"
21
+
22
+ // [START android_examples_wfp_validation]
23
+ val validator = DwfValidatorFactory .create()
24
+ val result = validator.validate(watchFaceFile, appPackageName)
25
+
26
+ if (result.failures().isEmpty()) {
27
+ val token = result.validationToken()
28
+ println (" Validation token: $token " )
29
+
30
+ // Validation success - continue with the token
31
+ // ...
32
+ } else {
33
+ // There were failures, handle them accordingly - validation has failed.
34
+ result.failures().forEach { failure ->
35
+ println (" FAILURE: ${failure.name()} : ${failure.failureMessage()} " )
36
+ // ...
37
+ }
38
+ }
39
+ // [END android_examples_wfp_validation]
40
+ }
41
+
42
+ private fun obtainTempWatchFaceFile (): File {
43
+ val resourceName = " watchface.apk"
44
+
45
+ val inputStream = object {}.javaClass.classLoader.getResourceAsStream(resourceName)
46
+
47
+ if (inputStream == null ) {
48
+ println (" Error: Cannot find resource '$resourceName '" )
49
+ exitProcess(1 )
50
+ }
51
+
52
+ val tempFile = File .createTempFile(" validator-" , " .apk" )
53
+ tempFile.deleteOnExit()
54
+
55
+ FileOutputStream (tempFile).use { fos ->
56
+ inputStream.copyTo(fos)
57
+ }
58
+ return tempFile
59
+ }
0 commit comments