gpt4 book ai didi

java - 如何在Android中将Barcode.CONTACT_INFO的地址类型转换为字符串类型?

转载 作者:行者123 更新时间:2023-12-01 18:35:06 26 4
gpt4 key购买 nike

我正在使用实现“com.google.android.gms:play-services-vision:19.0.0”库来扫描条形码,当它扫描 contactinfo QR 码时,它会给出虚拟值。地址、URL、电子邮件和电话给出了虚拟值,它没有转换为字符串值。

@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
final SparseArray<Barcode> barcodes = detections.getDetectedItems();
if (barcodes.size() != 0) {

for (int index = 0; index < barcodes.size(); index++) {
Barcode code = barcodes.valueAt(index);
int type = barcodes.valueAt(index).valueFormat;
switch (type) {
case Barcode.CONTACT_INFO:
String name = code.contactInfo.name.formattedName;
String title = code.contactInfo.title;
String organization = code.contactInfo.organization;
String address = code.contactInfo.addresses.toString();
String phone = code.contactInfo.phones.toString();
String emails = code.contactInfo.emails.toString();
String urls = code.contactInfo.urls.toString();

break;
}
}

}
}

最佳答案

请检查此文档。

https://developers.google.com/android/reference/com/google/android/gms/vision/barcode/Barcode.ContactInfo

public Address[] addresses  
public Email[] emails
public Phone[] phones
public String[] urls

这些值是数组,因此不能使用 toString() 函数。

您可以检查类(地址、电子邮件和电话)以从此文档中获取相应的值。

例如,要获取第一个电话号码,

Barcode.Phone[] phones = code.contactInfo.phones;
if (phones.length > 1) {
Barcode.Phone phone = phones[0];
String phoneNumber = phone.number;
}

希望对您有所帮助。

关于java - 如何在Android中将Barcode.CONTACT_INFO的地址类型转换为字符串类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60076475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com