|
6 | 6 | import android.net.Uri; |
7 | 7 | import android.os.Bundle; |
8 | 8 | import android.support.annotation.NonNull; |
| 9 | +import android.support.annotation.Nullable; |
9 | 10 | import android.support.v4.app.ActivityCompat; |
10 | 11 | import android.support.v4.content.ContextCompat; |
11 | 12 | import android.support.v7.app.AlertDialog; |
@@ -63,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) { |
63 | 64 | } |
64 | 65 | if (action.equals(Intent.ACTION_SEND)) { |
65 | 66 | 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; |
67 | 69 | progressStatus.setText(getString(R.string.progress_status_parsing_link)); |
68 | 70 | if (intentExtraText.endsWith(".jpg") || |
69 | 71 | intentExtraText.endsWith(".png") || |
@@ -114,6 +116,23 @@ protected void onCreate(Bundle savedInstanceState) { |
114 | 116 | } |
115 | 117 | } |
116 | 118 |
|
| 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 | + |
117 | 136 | @Override |
118 | 137 | public void onRequestPermissionsResult(int requestCode, |
119 | 138 | @NonNull String permissions[], |
@@ -142,6 +161,7 @@ private void handleImageSearch(Uri imageUri) throws FileNotFoundException { |
142 | 161 | AtomicReference<String> reverseSearchRedirectURL = new AtomicReference<>(); |
143 | 162 | AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); |
144 | 163 | asyncHttpClient.addHeader(API_USER_AGENT_KEY, FAKE_USER_AGENT); |
| 164 | + asyncHttpClient.setTimeout(30_000); |
145 | 165 | RequestParams requestParams = new RequestParams(); |
146 | 166 | requestParams.put(API_SCH_KEY, API_SCH_VALUE); |
147 | 167 | requestParams.put(API_ENCODED_IMAGE_KEY, Objects.requireNonNull(getContentResolver().openInputStream(imageUri))); |
|
0 commit comments