From 3218ff10f1b27942615fa1dd0d0ea5347a5ea64e Mon Sep 17 00:00:00 2001 From: Docile-Alligator Date: Mon, 30 May 2022 23:20:44 +0800 Subject: Share a link to Infinity so that you can open reddit links in this app. --- .../activities/LinkResolverActivity.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') 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())); -- cgit v1.2.3