Skip to content

Commit 5d10c05

Browse files
committed
Fixed issue with some application shares - URLs being handled incorrectly, increased timeout.
1 parent 42a1409 commit 5d10c05

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "eu.dasancti.reversee"
77
minSdkVersion 21
88
targetSdkVersion 28
9-
versionCode 2
10-
versionName "ALPHA v0.3"
9+
versionCode 3
10+
versionName "ALPHA v0.4"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/src/main/java/eu/dasancti/reversee/MainActivity.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.os.Bundle;
88
import android.support.annotation.NonNull;
9+
import android.support.annotation.Nullable;
910
import android.support.v4.app.ActivityCompat;
1011
import android.support.v4.content.ContextCompat;
1112
import android.support.v7.app.AlertDialog;
@@ -63,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) {
6364
}
6465
if (action.equals(Intent.ACTION_SEND)) {
6566
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
66-
String intentExtraText = intent.getParcelableExtra(Intent.EXTRA_TEXT).toString();
67+
String intentExtraText = getSharedURL(intent);
68+
if (intentExtraText == null) return;
6769
progressStatus.setText(getString(R.string.progress_status_parsing_link));
6870
if (intentExtraText.endsWith(".jpg") ||
6971
intentExtraText.endsWith(".png") ||
@@ -114,6 +116,23 @@ protected void onCreate(Bundle savedInstanceState) {
114116
}
115117
}
116118

119+
@Nullable
120+
private String getSharedURL(Intent intent) {
121+
Bundle extras = intent.getExtras();
122+
if (extras == null) {
123+
Toast.makeText(MainActivity.this, "Failed to get shared URL, incorrect format.", Toast.LENGTH_SHORT).show();
124+
this.finish();
125+
return null;
126+
}
127+
String intentExtraText = extras.getString(Intent.EXTRA_TEXT);
128+
if (intentExtraText == null) {
129+
Toast.makeText(MainActivity.this, "Failed to get URL from bundle, URL is empty or malformed", Toast.LENGTH_SHORT).show();
130+
this.finish();
131+
return null;
132+
}
133+
return intentExtraText;
134+
}
135+
117136
@Override
118137
public void onRequestPermissionsResult(int requestCode,
119138
@NonNull String permissions[],
@@ -142,6 +161,7 @@ private void handleImageSearch(Uri imageUri) throws FileNotFoundException {
142161
AtomicReference<String> reverseSearchRedirectURL = new AtomicReference<>();
143162
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
144163
asyncHttpClient.addHeader(API_USER_AGENT_KEY, FAKE_USER_AGENT);
164+
asyncHttpClient.setTimeout(30_000);
145165
RequestParams requestParams = new RequestParams();
146166
requestParams.put(API_SCH_KEY, API_SCH_VALUE);
147167
requestParams.put(API_ENCODED_IMAGE_KEY, Objects.requireNonNull(getContentResolver().openInputStream(imageUri)));

0 commit comments

Comments
 (0)