mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Fix encoding of certain Intents that don't have EXTRA_TEXT or EXTRA_STREAM
git-svn-id: https://zxing.googlecode.com/svn/trunk@2388 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
9add6f3992
commit
144321067c
|
@ -131,18 +131,32 @@ final class QRCodeEncoder {
|
||||||
// Handles send intents from multitude of Android applications
|
// Handles send intents from multitude of Android applications
|
||||||
private void encodeContentsFromShareIntent(Intent intent) throws WriterException {
|
private void encodeContentsFromShareIntent(Intent intent) throws WriterException {
|
||||||
// Check if this is a plain text encoding, or contact
|
// Check if this is a plain text encoding, or contact
|
||||||
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
|
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
|
||||||
encodeContentsFromShareIntentPlainText(intent);
|
encodeFromStreamExtra(intent);
|
||||||
} else {
|
} else {
|
||||||
// Attempt default sharing.
|
encodeFromTextExtras(intent);
|
||||||
encodeContentsFromShareIntentDefault(intent);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void encodeContentsFromShareIntentPlainText(Intent intent) throws WriterException {
|
private void encodeFromTextExtras(Intent intent) throws WriterException {
|
||||||
// Notice: Google Maps shares both URL and details in one text, bummer!
|
// Notice: Google Maps shares both URL and details in one text, bummer!
|
||||||
String theContents = ContactEncoder.trim(intent.getStringExtra(Intent.EXTRA_TEXT));
|
String theContents = ContactEncoder.trim(intent.getStringExtra(Intent.EXTRA_TEXT));
|
||||||
// We only support non-empty and non-blank texts.
|
if (theContents == null) {
|
||||||
|
theContents = ContactEncoder.trim(intent.getStringExtra("android.intent.extra.HTML_TEXT"));
|
||||||
|
// Intent.EXTRA_HTML_TEXT
|
||||||
|
if (theContents == null) {
|
||||||
|
theContents = ContactEncoder.trim(intent.getStringExtra(Intent.EXTRA_SUBJECT));
|
||||||
|
if (theContents == null) {
|
||||||
|
String[] emails = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
|
||||||
|
if (emails != null) {
|
||||||
|
theContents = ContactEncoder.trim(emails[0]);
|
||||||
|
} else {
|
||||||
|
theContents = "?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trim text to avoid URL breaking.
|
// Trim text to avoid URL breaking.
|
||||||
if (theContents == null || theContents.length() == 0) {
|
if (theContents == null || theContents.length() == 0) {
|
||||||
throw new WriterException("Empty EXTRA_TEXT");
|
throw new WriterException("Empty EXTRA_TEXT");
|
||||||
|
@ -161,7 +175,7 @@ final class QRCodeEncoder {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles send intents from the Contacts app, retrieving a contact as a VCARD.
|
// Handles send intents from the Contacts app, retrieving a contact as a VCARD.
|
||||||
private void encodeContentsFromShareIntentDefault(Intent intent) throws WriterException {
|
private void encodeFromStreamExtra(Intent intent) throws WriterException {
|
||||||
format = BarcodeFormat.QR_CODE;
|
format = BarcodeFormat.QR_CODE;
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
|
|
Loading…
Reference in a new issue