diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index e8d796ed5b16..61aeb6c469ad 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -2374,19 +2374,20 @@ abstract public class GeckoApp ((GeckoApplication) getApplication()).removeApplicationLifecycleCallbacks(this); } - // Get/Create a temporary direcory + // Get a temporary directory, may return null public static File getTempDirectory() { File dir = mAppContext.getExternalFilesDir("temp"); - dir.mkdirs(); return dir; } // Delete any files in our temporary directory public static void deleteTempFiles() { - File[] files = getTempDirectory().listFiles(); + File dir = getTempDirectory(); + if (dir == null) + return; + File[] files = dir.listFiles(); if (files == null) return; - for (File file : files) { file.delete(); } diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 180d7de0b0ad..cbea3fe1dd00 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -1042,8 +1042,13 @@ public class GeckoAppShell Intent intent = new Intent(Intent.ACTION_SEND); boolean isDataURI = aSrc.startsWith("data:"); OutputStream os = null; - File dir = GeckoApp.getTempDirectory(); + + if (dir == null) { + showImageShareFailureToast(); + return; + } + GeckoApp.deleteTempFiles(); try { @@ -1089,11 +1094,7 @@ public class GeckoAppShell intent.putExtra(Intent.EXTRA_TEXT, aSrc); intent.setType("text/plain"); } else { - // Don't fail silently, tell the user that we weren't able to share the image - Toast toast = Toast.makeText(GeckoApp.mAppContext, - GeckoApp.mAppContext.getResources().getString(R.string.share_image_failed), - Toast.LENGTH_SHORT); - toast.show(); + showImageShareFailureToast(); return; } } finally { @@ -1103,6 +1104,14 @@ public class GeckoAppShell GeckoApp.mAppContext.getResources().getString(R.string.share_title))); } + // Don't fail silently, tell the user that we weren't able to share the image + private static final void showImageShareFailureToast() { + Toast toast = Toast.makeText(GeckoApp.mAppContext, + GeckoApp.mAppContext.getResources().getString(R.string.share_image_failed), + Toast.LENGTH_SHORT); + toast.show(); + } + static boolean openUriExternal(String aUriSpec, String aMimeType, String aPackageName, String aClassName, String aAction, String aTitle) { Intent intent = getIntentForActionString(aAction);