找到了示例应用程序
https://github.com/android/identity-samples/tree/main/AccountTransferApi
显然,他们所做的是将帐户信息放入JSON obj中,然后将JSON obj转换为字节数组(即transferData)。
val jsonArray = JSONArray()
for (account in accounts) {
val accountJsonObject = JSONObject()
try {
accountJsonObject.put(KEY_ACCOUNT_NAME, account.name)
val password = accountManager.getPassword(account)
accountJsonObject.put(KEY_ACCOUNT_PASSWORD, password)
} catch (e: JSONException) {
Log.e(TAG, "Error while creating bytes for transfer", e)
return null
}
jsonArray.put(accountJsonObject)
}
val jsonObject = JSONObject()
try {
jsonObject.put(KEY_ACCOUNT_ARRAY, jsonArray)
} catch (e: JSONException) {
Log.e(TAG, "Error", e)
return null
}
val transferData = jsonObject.toString().toByteArray(Charset.forName("UTF-8"))
无论如何,强烈推荐示例应用程序。文档不够清晰!