Browse Source

Open urls in new browser tabs. Closes https://github.com/austinhuang0131/barinsta/issues/367

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
e4c30c0389
  1. 9
      app/src/main/java/awais/instagrabber/utils/Utils.java
  2. 1
      app/src/main/res/values/strings.xml

9
app/src/main/java/awais/instagrabber/utils/Utils.java

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.provider.Browser;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
@ -181,12 +182,14 @@ public final class Utils {
if (context == null || TextUtils.isEmpty(url)) { if (context == null || TextUtils.isEmpty(url)) {
return; return;
} }
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
final Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
i.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
i.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
try { try {
context.startActivity(i); context.startActivity(i);
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Log.e(TAG, "openURL: No activity found to handle URL view", e);
Log.e(TAG, "openURL: No activity found to handle URLs", e);
Toast.makeText(context, context.getString(R.string.no_external_app_url), Toast.LENGTH_LONG).show();
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "openURL", e); Log.e(TAG, "openURL", e);
} }

1
app/src/main/res/values/strings.xml

@ -310,6 +310,7 @@
<string name="disable_animation">Disable animation</string> <string name="disable_animation">Disable animation</string>
<string name="follower_wait_to_load">Please wait for the current task to complete first!</string> <string name="follower_wait_to_load">Please wait for the current task to complete first!</string>
<string name="post_not_found">Post not found!</string> <string name="post_not_found">Post not found!</string>
<string name="no_external_app_url">No app found which opens urls</string>
<plurals name="likes_count"> <plurals name="likes_count">
<item quantity="one">%d like</item> <item quantity="one">%d like</item>
<item quantity="other">%d likes</item> <item quantity="other">%d likes</item>

Loading…
Cancel
Save