From f786d020e65abcdfc08a70600dc82d3f1a97ebf8 Mon Sep 17 00:00:00 2001 From: jnlon Date: Thu, 29 Aug 2019 12:32:26 -0400 Subject: [PATCH] Fix ActivityNotFound crash on local HTML files This resolves a crash when there is no HTML viewer/browser that can handle file:// URLs --- .../pocketgopher/gopherclient/HtmlPage.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/gmail/afonsotrepa/pocketgopher/gopherclient/HtmlPage.java b/app/src/main/java/com/gmail/afonsotrepa/pocketgopher/gopherclient/HtmlPage.java index dab7a44..a15368a 100644 --- a/app/src/main/java/com/gmail/afonsotrepa/pocketgopher/gopherclient/HtmlPage.java +++ b/app/src/main/java/com/gmail/afonsotrepa/pocketgopher/gopherclient/HtmlPage.java @@ -118,11 +118,17 @@ public void run() { try { + // attempt file connect/download (possible IOEXception) Connection conn = new Connection(page.server, page.port); conn.getBinary(page.selector, file); + // attempt view intent (possible ActivityNotFoundException) + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.fromFile(file)); + context.startActivity(intent); } - catch (final IOException e) + catch (final IOException | ActivityNotFoundException e) { e.printStackTrace(); //inform the user of the error @@ -139,11 +145,6 @@ public void run() } }); } - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - intent.setData(Uri.fromFile(file)); - context.startActivity(intent); } }).start(); } @@ -155,4 +156,4 @@ public void run() Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); } } -} \ No newline at end of file +}