diff options
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index d1589c18..79904bbc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -7,6 +7,7 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Bundle; +import android.webkit.URLUtil; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; @@ -74,6 +75,21 @@ public class LinkResolverActivity extends AppCompatActivity { ((Infinity) getApplication()).getAppComponent().inject(this); Uri uri = getIntent().getData(); + if (uri == null) { + String url = getIntent().getStringExtra(Intent.EXTRA_TEXT); + if (!URLUtil.isValidUrl(url)) { + Toast.makeText(this, R.string.invalid_link, Toast.LENGTH_SHORT).show(); + finish(); + return; + } + try { + uri = Uri.parse(url); + } catch (NullPointerException e) { + Toast.makeText(this, R.string.invalid_link, Toast.LENGTH_SHORT).show(); + finish(); + return; + } + } if (uri.getScheme() == null && uri.getHost() == null) { handleUri(getRedditUriByPath(uri.toString())); |