|
7 | 7 | import android.content.SharedPreferences; |
8 | 8 | import android.database.CursorIndexOutOfBoundsException; |
9 | 9 | import android.database.sqlite.SQLiteDatabase; |
| 10 | +import android.net.Uri; |
10 | 11 | import android.os.Build; |
11 | 12 | import android.os.Bundle; |
12 | 13 | import android.util.DisplayMetrics; |
@@ -445,32 +446,48 @@ private void onSharedIntent(Intent intent) { |
445 | 446 | String receivedAction = intent.getAction(); |
446 | 447 | String receivedType = intent.getType(); |
447 | 448 |
|
448 | | - // Check if an image or file was shared to us |
449 | | - if (Intent.ACTION_SEND.equals(receivedAction)) { |
450 | | - List<ParseResult> parseResultList; |
| 449 | + if (receivedAction == null || receivedType == null) { |
| 450 | + return; |
| 451 | + } |
451 | 452 |
|
452 | | - if (receivedType.equals("text/plain")) { |
453 | | - LoyaltyCard loyaltyCard = new LoyaltyCard(); |
454 | | - loyaltyCard.setCardId(intent.getStringExtra(Intent.EXTRA_TEXT)); |
455 | | - parseResultList = Collections.singletonList(new ParseResult(ParseResultType.BARCODE_ONLY, loyaltyCard)); |
456 | | - } else if (receivedType.startsWith("image/")) { |
457 | | - parseResultList = Utils.retrieveBarcodesFromImage(this, intent.getParcelableExtra(Intent.EXTRA_STREAM)); |
458 | | - } else if (receivedType.equals("application/pdf")) { |
459 | | - parseResultList = Utils.retrieveBarcodesFromPdf(this, intent.getParcelableExtra(Intent.EXTRA_STREAM)); |
460 | | - } else if (receivedType.equals("application/vnd.apple.pkpass")) { |
461 | | - parseResultList = Utils.retrieveBarcodesFromPkPass(this, intent.getParcelableExtra(Intent.EXTRA_STREAM)); |
| 453 | + List<ParseResult> parseResultList; |
| 454 | + |
| 455 | + // Check for shared text |
| 456 | + if (receivedAction.equals(Intent.ACTION_SEND) && receivedType.equals("text/plain")) { |
| 457 | + LoyaltyCard loyaltyCard = new LoyaltyCard(); |
| 458 | + loyaltyCard.setCardId(intent.getStringExtra(Intent.EXTRA_TEXT)); |
| 459 | + parseResultList = Collections.singletonList(new ParseResult(ParseResultType.BARCODE_ONLY, loyaltyCard)); |
| 460 | + } else { |
| 461 | + // Parse whatever file was sent, regardless of opening or sharing |
| 462 | + Uri data; |
| 463 | + if (receivedAction.equals(Intent.ACTION_VIEW)) { |
| 464 | + data = intent.getData(); |
| 465 | + } else if (receivedAction.equals(Intent.ACTION_SEND)) { |
| 466 | + data = intent.getParcelableExtra(Intent.EXTRA_STREAM); |
462 | 467 | } else { |
463 | | - Log.e(TAG, "Wrong mime-type"); |
| 468 | + Log.e(TAG, "Wrong action type to parse intent"); |
464 | 469 | return; |
465 | 470 | } |
466 | 471 |
|
467 | | - if (parseResultList.isEmpty()) { |
468 | | - finish(); |
| 472 | + if (receivedType.startsWith("image/")) { |
| 473 | + parseResultList = Utils.retrieveBarcodesFromImage(this, data); |
| 474 | + } else if (receivedType.equals("application/pdf")) { |
| 475 | + parseResultList = Utils.retrieveBarcodesFromPdf(this, data); |
| 476 | + } else if (receivedType.equals("application/vnd.apple.pkpass")) { |
| 477 | + parseResultList = Utils.retrieveBarcodesFromPkPass(this, data); |
| 478 | + } else { |
| 479 | + Log.e(TAG, "Wrong mime-type"); |
469 | 480 | return; |
470 | 481 | } |
| 482 | + } |
471 | 483 |
|
472 | | - processParseResultList(parseResultList, null, true); |
| 484 | + // Give up if we should parse but there is nothing to parse |
| 485 | + if (parseResultList == null || parseResultList.isEmpty()) { |
| 486 | + finish(); |
| 487 | + return; |
473 | 488 | } |
| 489 | + |
| 490 | + processParseResultList(parseResultList, null, true); |
474 | 491 | } |
475 | 492 |
|
476 | 493 | private void extractIntentFields(Intent intent) { |
|
0 commit comments