mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
More logging, care with parsing vCard?
git-svn-id: https://zxing.googlecode.com/svn/trunk@1393 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
1ef423bf68
commit
b789f32c71
|
@ -39,7 +39,6 @@ import android.provider.Contacts;
|
||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
@ -141,22 +140,25 @@ final class QRCodeEncoder {
|
||||||
InputStream stream = activity.getContentResolver().openInputStream(uri);
|
InputStream stream = activity.getContentResolver().openInputStream(uri);
|
||||||
int length = stream.available();
|
int length = stream.available();
|
||||||
byte[] vcard = new byte[length];
|
byte[] vcard = new byte[length];
|
||||||
stream.read(vcard, 0, length);
|
int bytesRead = stream.read(vcard, 0, length);
|
||||||
String vcardString = new String(vcard, "UTF-8");
|
String vcardString = new String(vcard, 0, bytesRead, "UTF-8");
|
||||||
Log.d(TAG, "Encoding share intent content: " + vcardString);
|
Log.d(TAG, "Encoding share intent content:");
|
||||||
|
Log.d(TAG, vcardString);
|
||||||
Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
|
Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
|
||||||
ParsedResult parsedResult = ResultParser.parseResult(result);
|
ParsedResult parsedResult = ResultParser.parseResult(result);
|
||||||
if (!(parsedResult instanceof AddressBookParsedResult)) {
|
if (!(parsedResult instanceof AddressBookParsedResult)) {
|
||||||
|
Log.d(TAG, "Result was not an address");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!encodeQRCodeContents((AddressBookParsedResult) parsedResult)) {
|
if (!encodeQRCodeContents((AddressBookParsedResult) parsedResult)) {
|
||||||
|
Log.d(TAG, "Unable to encode contents");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return false;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
return false;
|
return false;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
// In case the uri was not found in the Intent.
|
// In case the uri was not found in the Intent.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -259,17 +261,16 @@ final class QRCodeEncoder {
|
||||||
}
|
}
|
||||||
String[] addresses = contact.getAddresses();
|
String[] addresses = contact.getAddresses();
|
||||||
if (addresses != null) {
|
if (addresses != null) {
|
||||||
for (int x = 0; x < addresses.length; x++) {
|
for (String address : addresses) {
|
||||||
if (addresses[x] != null && addresses[x].length() > 0) {
|
if (address != null && address.length() > 0) {
|
||||||
newContents.append("ADR:").append(addresses[x]).append(';');
|
newContents.append("ADR:").append(address).append(';');
|
||||||
newDisplayContents.append('\n').append(addresses[x]);
|
newDisplayContents.append('\n').append(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] phoneNumbers = contact.getPhoneNumbers();
|
String[] phoneNumbers = contact.getPhoneNumbers();
|
||||||
if (phoneNumbers != null) {
|
if (phoneNumbers != null) {
|
||||||
for (int x = 0; x < phoneNumbers.length; x++) {
|
for (String phone : phoneNumbers) {
|
||||||
String phone = phoneNumbers[x];
|
|
||||||
if (phone != null && phone.length() > 0) {
|
if (phone != null && phone.length() > 0) {
|
||||||
newContents.append("TEL:").append(phone).append(';');
|
newContents.append("TEL:").append(phone).append(';');
|
||||||
newDisplayContents.append('\n').append(PhoneNumberUtils.formatNumber(phone));
|
newDisplayContents.append('\n').append(PhoneNumberUtils.formatNumber(phone));
|
||||||
|
@ -278,8 +279,7 @@ final class QRCodeEncoder {
|
||||||
}
|
}
|
||||||
String[] emails = contact.getEmails();
|
String[] emails = contact.getEmails();
|
||||||
if (emails != null) {
|
if (emails != null) {
|
||||||
for (int x = 0; x < emails.length; x++) {
|
for (String email : emails) {
|
||||||
String email = emails[x];
|
|
||||||
if (email != null && email.length() > 0) {
|
if (email != null && email.length() > 0) {
|
||||||
newContents.append("EMAIL:").append(email).append(';');
|
newContents.append("EMAIL:").append(email).append(';');
|
||||||
newDisplayContents.append('\n').append(email);
|
newDisplayContents.append('\n').append(email);
|
||||||
|
|
Loading…
Reference in a new issue