diff --git a/app/build.gradle b/app/build.gradle index c723c86..a166889 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "eu.dasancti.reversee" minSdkVersion 21 targetSdkVersion 28 - versionCode 2 - versionName "ALPHA v0.3" + versionCode 3 + versionName "ALPHA v0.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/app/src/main/java/eu/dasancti/reversee/MainActivity.java b/app/src/main/java/eu/dasancti/reversee/MainActivity.java index c85269c..d494064 100644 --- a/app/src/main/java/eu/dasancti/reversee/MainActivity.java +++ b/app/src/main/java/eu/dasancti/reversee/MainActivity.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; @@ -63,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) { } if (action.equals(Intent.ACTION_SEND)) { if (intent.hasExtra(Intent.EXTRA_TEXT)) { - String intentExtraText = intent.getParcelableExtra(Intent.EXTRA_TEXT).toString(); + String intentExtraText = getSharedURL(intent); + if (intentExtraText == null) return; progressStatus.setText(getString(R.string.progress_status_parsing_link)); if (intentExtraText.endsWith(".jpg") || intentExtraText.endsWith(".png") || @@ -114,6 +116,23 @@ protected void onCreate(Bundle savedInstanceState) { } } + @Nullable + private String getSharedURL(Intent intent) { + Bundle extras = intent.getExtras(); + if (extras == null) { + Toast.makeText(MainActivity.this, "Failed to get shared URL, incorrect format.", Toast.LENGTH_SHORT).show(); + this.finish(); + return null; + } + String intentExtraText = extras.getString(Intent.EXTRA_TEXT); + if (intentExtraText == null) { + Toast.makeText(MainActivity.this, "Failed to get URL from bundle, URL is empty or malformed", Toast.LENGTH_SHORT).show(); + this.finish(); + return null; + } + return intentExtraText; + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @@ -142,6 +161,7 @@ private void handleImageSearch(Uri imageUri) throws FileNotFoundException { AtomicReference reverseSearchRedirectURL = new AtomicReference<>(); AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); asyncHttpClient.addHeader(API_USER_AGENT_KEY, FAKE_USER_AGENT); + asyncHttpClient.setTimeout(30_000); RequestParams requestParams = new RequestParams(); requestParams.put(API_SCH_KEY, API_SCH_VALUE); requestParams.put(API_ENCODED_IMAGE_KEY, Objects.requireNonNull(getContentResolver().openInputStream(imageUri)));