Skip to content

Commit e409b86

Browse files
[android] Ask for action after reading CHIP NFC Tag (project-chip#4425)
When NFC Tag containing commissioning information of a CHIP device is read, ask a user for an action to take: - display the device information - provision into a Wi-Fi network - provision into a Thread network
1 parent 75c68c6 commit e409b86

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/android/CHIPTool/app/src/main/java/com/google/chip/chiptool/CHIPToolActivity.kt

+24-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.content.Intent
2121
import android.nfc.NdefMessage
2222
import android.nfc.NfcAdapter
2323
import android.os.Bundle
24+
import androidx.appcompat.app.AlertDialog
2425
import androidx.appcompat.app.AppCompatActivity
2526
import androidx.fragment.app.Fragment
2627
import chip.setuppayload.SetupPayloadParser
@@ -146,15 +147,31 @@ class CHIPToolActivity :
146147

147148
val setupPayload = SetupPayloadParser().parseQrCode(uri.toString().toUpperCase())
148149
val deviceInfo = CHIPDeviceInfo(
149-
setupPayload.version,
150-
setupPayload.vendorId,
151-
setupPayload.productId,
152-
setupPayload.discriminator,
153-
setupPayload.setupPinCode,
154-
setupPayload.optionalQRCodeInfo.mapValues { (_, info) -> QrCodeInfo(info.tag, info.type, info.data, info.int32) }
150+
setupPayload.version,
151+
setupPayload.vendorId,
152+
setupPayload.productId,
153+
setupPayload.discriminator,
154+
setupPayload.setupPinCode,
155+
setupPayload.optionalQRCodeInfo.mapValues { (_, info) -> QrCodeInfo(info.tag, info.type, info.data, info.int32) }
155156
)
156157

157-
onCHIPDeviceInfoReceived(deviceInfo)
158+
val buttons = arrayOf(
159+
getString(R.string.nfc_tag_action_show),
160+
getString(R.string.nfc_tag_action_wifi),
161+
getString(R.string.nfc_tag_action_thread))
162+
163+
AlertDialog.Builder(this)
164+
.setTitle(R.string.nfc_tag_action_title)
165+
.setItems(buttons) { _, which ->
166+
this.networkType = when (which) {
167+
1 -> ProvisionNetworkType.WIFI
168+
2 -> ProvisionNetworkType.THREAD
169+
else -> null
170+
}
171+
onCHIPDeviceInfoReceived(deviceInfo)
172+
}
173+
.create()
174+
.show()
158175
}
159176

160177
companion object {

src/android/CHIPTool/app/src/main/res/values/strings.xml

+5
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@
8282
<string name="enter_thread_master_key_text">00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF</string>
8383
<string name="enter_thread_save_network_btn">Save network</string>
8484

85+
<string name="nfc_tag_action_title">CHIP NFC Tag read. Choose an action:</string>
86+
<string name="nfc_tag_action_show">Show device information</string>
87+
<string name="nfc_tag_action_wifi">Provision into Wi-Fi network</string>
88+
<string name="nfc_tag_action_thread">Provision into Thread network</string>
89+
8590
</resources>

0 commit comments

Comments
 (0)