diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ee705524c..ccf5521a8 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -40,9 +40,20 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/java/protect/card_locker/MainActivity.java b/app/src/main/java/protect/card_locker/MainActivity.java
index 4020ef495..b8c96d9a8 100644
--- a/app/src/main/java/protect/card_locker/MainActivity.java
+++ b/app/src/main/java/protect/card_locker/MainActivity.java
@@ -7,6 +7,7 @@
import android.content.SharedPreferences;
import android.database.CursorIndexOutOfBoundsException;
import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
@@ -445,32 +446,48 @@ private void onSharedIntent(Intent intent) {
String receivedAction = intent.getAction();
String receivedType = intent.getType();
- // Check if an image or file was shared to us
- if (Intent.ACTION_SEND.equals(receivedAction)) {
- List parseResultList;
+ if (receivedAction == null || receivedType == null) {
+ return;
+ }
- if (receivedType.equals("text/plain")) {
- LoyaltyCard loyaltyCard = new LoyaltyCard();
- loyaltyCard.setCardId(intent.getStringExtra(Intent.EXTRA_TEXT));
- parseResultList = Collections.singletonList(new ParseResult(ParseResultType.BARCODE_ONLY, loyaltyCard));
- } else if (receivedType.startsWith("image/")) {
- parseResultList = Utils.retrieveBarcodesFromImage(this, intent.getParcelableExtra(Intent.EXTRA_STREAM));
- } else if (receivedType.equals("application/pdf")) {
- parseResultList = Utils.retrieveBarcodesFromPdf(this, intent.getParcelableExtra(Intent.EXTRA_STREAM));
- } else if (receivedType.equals("application/vnd.apple.pkpass")) {
- parseResultList = Utils.retrieveBarcodesFromPkPass(this, intent.getParcelableExtra(Intent.EXTRA_STREAM));
+ List parseResultList;
+
+ // Check for shared text
+ if (receivedAction.equals(Intent.ACTION_SEND) && receivedType.equals("text/plain")) {
+ LoyaltyCard loyaltyCard = new LoyaltyCard();
+ loyaltyCard.setCardId(intent.getStringExtra(Intent.EXTRA_TEXT));
+ parseResultList = Collections.singletonList(new ParseResult(ParseResultType.BARCODE_ONLY, loyaltyCard));
+ } else {
+ // Parse whatever file was sent, regardless of opening or sharing
+ Uri data;
+ if (receivedAction.equals(Intent.ACTION_VIEW)) {
+ data = intent.getData();
+ } else if (receivedAction.equals(Intent.ACTION_SEND)) {
+ data = intent.getParcelableExtra(Intent.EXTRA_STREAM);
} else {
- Log.e(TAG, "Wrong mime-type");
+ Log.e(TAG, "Wrong action type to parse intent");
return;
}
- if (parseResultList.isEmpty()) {
- finish();
+ if (receivedType.startsWith("image/")) {
+ parseResultList = Utils.retrieveBarcodesFromImage(this, data);
+ } else if (receivedType.equals("application/pdf")) {
+ parseResultList = Utils.retrieveBarcodesFromPdf(this, data);
+ } else if (receivedType.equals("application/vnd.apple.pkpass")) {
+ parseResultList = Utils.retrieveBarcodesFromPkPass(this, data);
+ } else {
+ Log.e(TAG, "Wrong mime-type");
return;
}
+ }
- processParseResultList(parseResultList, null, true);
+ // Give up if we should parse but there is nothing to parse
+ if (parseResultList == null || parseResultList.isEmpty()) {
+ finish();
+ return;
}
+
+ processParseResultList(parseResultList, null, true);
}
private void extractIntentFields(Intent intent) {