Skip to content

Commit

Permalink
Merge pull request #3963 from gustamor/bugfix/3756
Browse files Browse the repository at this point in the history
Fix issue ActivityNotFoundException on Utils#openURL
  • Loading branch information
VishalNehra authored Oct 30, 2023
2 parents 4161845 + 093ae42 commit 68a1f93
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 4 deletions.
27 changes: 26 additions & 1 deletion app/src/main/java/com/amaze/filemanager/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
import java.io.File;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amaze.filemanager.BuildConfig;
import com.amaze.filemanager.R;
import com.amaze.filemanager.adapters.data.LayoutElementParcelable;
Expand All @@ -39,13 +43,16 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.storage.StorageVolume;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -89,6 +96,9 @@ public class Utils {
public static final String EMAIL_NOREPLY_REPORTS = "[email protected]";
public static final String EMAIL_SUPPORT = "[email protected]";

private static final Logger log = LoggerFactory.getLogger(Utils.class);
private static boolean isToastShowing = false;

// methods for fastscroller
public static float clamp(float min, float max, float value) {
float minimum = Math.max(min, value);
Expand Down Expand Up @@ -378,7 +388,22 @@ public static Snackbar showCutCopySnackBar(
public static void openURL(String url, Context context) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
context.startActivity(intent);

PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> webViews =
packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

if (!webViews.isEmpty()) {
context.startActivity(intent);
} else {
log.warn("A browser is not available");
if (!isToastShowing) {
isToastShowing = true;
Toast.makeText(context, R.string.not_found_enabled_webview, Toast.LENGTH_SHORT).show();
// Prevents a myriad of duplicates
new Handler().postDelayed(() -> isToastShowing = false, 2200);
}
}
}

/** Open telegram in browser */
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values-ast-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,5 +407,8 @@ to ordenador.</li><li/><br/>\\n
<string name="blue">Azul</string>
<string name="green">Verde</string>
<string name="close">Zarrar</string>
</resources>

<string name="not_found_enabled_webview">Nun s\'atopó navegador disponible</string>

</resources>

3 changes: 2 additions & 1 deletion app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -555,5 +555,6 @@
<string name="scp_port">Pordo</string>
<string name="deselect_all">Elekti neniun</string>
<string name="got_it">Ĉu vi!</string>
</resources>
<string name="not_found_enabled_webview">Neniu navigilo troviĝis havebla</string>
</resources>

1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -684,5 +684,6 @@
Solo necesita hacer esto una vez, hasta la siguiente vez que seleccione una nueva ubicación para compartir.</string>
<string name="quick_desc">Archivos accedidos recientemente usando Amaze</string>
<string name="recent_desc">Archivos creados o modificados recientemente</string>
<string name="not_found_enabled_webview">No se encontró un navegador disponible</string>
</resources>

1 change: 1 addition & 0 deletions app/src/main/res/values-eu-rES/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,5 @@
<string name="unknown">ezezaguna</string>
<string name="multiple_invalid_archive_entries">Artxiboko zenbait fitxategi ezin dira erauzi; artxiboa hondatua egon daiteke edo jatorri maltzurrekoa izan daiteke.</string>
<string name="saf_otg_explanation">Androiden fitxategi-sistemara joango zara orain segurtasun arrazoiengatik. Hautatu USB gailua ezkerreko zerrendatik.</string>
<string name="not_found_enabled_webview">Ez da nabigatzaile erabilgaririk aurkitu</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,5 +654,6 @@
<string name="clear_open_file_summary">Efface les applications d\'ouverture de fichiers sélectionnées par défaut</string>
<string name="legacy_listing_title">Utiliser l\'ancien affichage pour root</string>
<string name="error_permission_denied">Permission refusée</string>
</resources>
<string name="not_found_enabled_webview">Aucun navigateur n\'a été trouvé disponible</string>
</resources>

1 change: 1 addition & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -667,5 +667,6 @@
<string name="error_permission_denied">Permissão negada</string>
<string name="quick_desc">Arquivos recentemente acessados pelo Amaze</string>
<string name="recent_desc">Arquivos criados ou modificados recentemente</string>
<string name="not_found_enabled_webview">Nenhum navegador encontrado</string>
</resources>

4 changes: 4 additions & 0 deletions app/src/main/res/values-pt-rPT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,5 +391,9 @@ Se inativa, será procurada qualquer correspondência.</string>
<string name="close">Fechar</string>
<string name="quick_desc">Ficheiros acedidos recentemente pelo Amaze</string>
<string name="recent_desc">Ficheiros recentemente criados ou modificados</string>

<!-- error messages -->
<string name="not_found_enabled_webview">Nenhum navegador encontrado</string>

</resources>

2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -817,5 +817,7 @@ You only need to do this once, until the next time you select a new location for
<string name="complete_paste_warning">Please complete paste operation first</string>
<string name="same_dir_move_error">Destination and source folder shouldn\'t match to move.</string>
<string name="checking_conflicts">Checking for conflicts</string>
<string name="same_dir_overwrite_error">Destination and source folder shouldn\'t match to overwrite.</string>
<string name="not_found_enabled_webview">No available browser</string>
</resources>

0 comments on commit 68a1f93

Please sign in to comment.