public void onActivityResult(Uri fileUri) {
// Only save the webpage archive if the file URI is not null, which happens if the user exited the file picker by pressing back.
if (fileUri != null) {
+ // Initialize the file name string from the file URI last path segment.
+ String temporaryFileNameString = fileUri.getLastPathSegment();
+
+ // Query the exact file name if the API >= 26.
+ if (Build.VERSION.SDK_INT >= 26) {
+ // Get a cursor from the content resolver.
+ Cursor contentResolverCursor = resultLauncherActivityHandle.getContentResolver().query(fileUri, null, null, null);
+
+ // Move to the fist row.
+ contentResolverCursor.moveToFirst();
+
+ // Get the file name from the cursor.
+ temporaryFileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
+
+ // Close the cursor.
+ contentResolverCursor.close();
+ }
+
+ // Save the final file name string so it can be used inside the lambdas. This will no longer be needed once this activity has transitioned to Kotlin.
+ String finalFileNameString = temporaryFileNameString;
+
try {
// Create a temporary MHT file.
File temporaryMhtFile = File.createTempFile("temporary_mht_file", ".mht", getCacheDir());
-
- // Save the temporary MHT file.
currentWebView.saveWebArchive(temporaryMhtFile.toString(), false, callbackValue -> {
if (callbackValue != null) { // The temporary MHT file was saved successfully.
try {
mhtOutputStream.close();
temporaryMhtFileInputStream.close();
- // Initialize the file name string from the file URI last path segment.
- String fileNameString = fileUri.getLastPathSegment();
-
- // Query the exact file name if the API >= 26.
- if (Build.VERSION.SDK_INT >= 26) {
- // Get a cursor from the content resolver.
- Cursor contentResolverCursor = resultLauncherActivityHandle.getContentResolver().query(fileUri, null, null, null);
-
- // Move to the fist row.
- contentResolverCursor.moveToFirst();
-
- // Get the file name from the cursor.
- fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
-
- // Close the cursor.
- contentResolverCursor.close();
- }
-
// Display a snackbar.
- Snackbar.make(currentWebView, getString(R.string.file_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(currentWebView, getString(R.string.saved, finalFileNameString), Snackbar.LENGTH_SHORT).show();
} catch (Exception exception) {
// Display a snackbar with the exception.
- Snackbar.make(currentWebView, getString(R.string.error_saving_file) + " " + exception, Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, exception), Snackbar.LENGTH_INDEFINITE).show();
} finally {
// Delete the temporary MHT file.
//noinspection ResultOfMethodCallIgnored
}
} else { // There was an unspecified error while saving the temporary MHT file.
// Display an error snackbar.
- Snackbar.make(currentWebView, getString(R.string.error_saving_file), Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, getString(R.string.unknown_error)), Snackbar.LENGTH_INDEFINITE).show();
}
});
} catch (IOException ioException) {
// Display a snackbar with the IO exception.
- Snackbar.make(currentWebView, getString(R.string.error_saving_file) + " " + ioException, Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(currentWebView, getString(R.string.error_saving_file, finalFileNameString, ioException), Snackbar.LENGTH_INDEFINITE).show();
}
}
}
// Display a file creation disposition snackbar.
if (fileCreationDisposition.equals(SUCCESS)) {
// Create a file saved snackbar.
- Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.file_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.saved, fileNameString), Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.error_saving_file) + " " + fileCreationDisposition, Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(aboutVersionLinearLayout, activity.getString(R.string.error_saving_file, fileNameString, fileCreationDisposition), Snackbar.LENGTH_INDEFINITE).show();
}
}
}
// Display a save disposition snackbar.
if (saveDisposition.equals(SUCCESS)) {
// Display the file saved snackbar.
- Snackbar.make(noSwipeViewPager, activity.getString(R.string.file_saved) + " " + fileNameString, Snackbar.LENGTH_LONG).show();
+ Snackbar.make(noSwipeViewPager, activity.getString(R.string.saved, fileNameString), Snackbar.LENGTH_LONG).show();
} else {
// Display the file saving error.
- Snackbar.make(noSwipeViewPager, activity.getString(R.string.error_saving_file) + " " + saveDisposition, Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(noSwipeViewPager, activity.getString(R.string.error_saving_file, fileNameString, saveDisposition), Snackbar.LENGTH_INDEFINITE).show();
}
}
}
/*
- * Copyright © 2019-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright0 2019-2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
*
// Display a file creation disposition snackbar.
if (fileCreationDisposition.equals(SUCCESS)) {
// Display the image saved snackbar.
- Snackbar.make(nestedScrollWebView, activity.getString(R.string.image_saved) + " " + fileNameString, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(nestedScrollWebView, activity.getString(R.string.saved, fileNameString), Snackbar.LENGTH_SHORT).show();
} else {
// Display the file saving error.
- Snackbar.make(nestedScrollWebView, activity.getString(R.string.error_saving_file) + " " + fileCreationDisposition, Snackbar.LENGTH_INDEFINITE).show();
+ Snackbar.make(nestedScrollWebView, activity.getString(R.string.error_saving_file, fileNameString, fileCreationDisposition), Snackbar.LENGTH_INDEFINITE).show();
}
}
-}
\ No newline at end of file
+}
private val saveAboutVersionTextActivityResultLauncher = registerForActivityResult(ActivityResultContracts.CreateDocument("text/plain")) { fileUri: Uri? ->
// Only save the file if the URI is not null, which happens if the user exited the file picker by pressing back.
if (fileUri != null) {
+ // Initialize the file name string from the file URI last path segment.
+ var fileNameString = fileUri.lastPathSegment
+
+ // Query the exact file name if the API >= 26.
+ if (Build.VERSION.SDK_INT >= 26) {
+ // Get a cursor from the content resolver.
+ val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!!
+
+ // Move to the first row.
+ contentResolverCursor.moveToFirst()
+
+ // Get the file name from the cursor.
+ fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
+
+ // Close the cursor.
+ contentResolverCursor.close()
+ }
+
try {
// Get the about version string.
val aboutVersionString = getAboutVersionString()
}
}
- // Initialize the file name string from the file URI last path segment.
- var fileNameString = fileUri.lastPathSegment
-
- // Query the exact file name if the API >= 26.
- if (Build.VERSION.SDK_INT >= 26) {
- // Get a cursor from the content resolver.
- val contentResolverCursor = requireActivity().contentResolver.query(fileUri, null, null, null)!!
-
- // Move to the first row.
- contentResolverCursor.moveToFirst()
-
- // Get the file name from the cursor.
- fileNameString = contentResolverCursor.getString(contentResolverCursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME))
-
- // Close the cursor.
- contentResolverCursor.close()
- }
-
// Display a snackbar with the saved logcat information.
Snackbar.make(aboutVersionLayout, getString(R.string.saved, fileNameString), Snackbar.LENGTH_SHORT).show()
} catch (exception: Exception) {
// Display a snackbar with the error message.
- Snackbar.make(aboutVersionLayout, getString(R.string.error_saving_file, exception.toString()), Snackbar.LENGTH_INDEFINITE).show()
+ Snackbar.make(aboutVersionLayout, getString(R.string.error_saving_file, fileNameString, exception.toString()), Snackbar.LENGTH_INDEFINITE).show()
}
}
}
<string name="unknown_size">Unbekannte Größe</string>
<string name="invalid_url">Ungültige URL</string>
<string name="saving_file">Speichere Datei:</string>
- <string name="file_saved">Datei gespeichert:</string>
<string name="processing_image">Bild wird bearbeitet… :</string>
- <string name="image_saved">Bild gespeichert:</string>
- <string name="error_saving_file">Fehler beim Speichern der Datei: \u0020 %1$sFf</string>
<!-- View Source. -->
<string name="request_headers">Anfragekopfzeilen</string>
<string name="swipe_to_refresh">Herunterziehen zum Aktualisieren</string>
<string name="swipe_to_refresh_summary">Einige Websites funktionieren nicht, wenn "Herunterziehen zum Aktualisieren" eingeschaltet ist.</string>
<string name="download_with_external_app">Mit einer externen App herunterladen</string>
- <string name="download_with_external_app_summary">Eine externe App verwenden, um Dateien herunterzuladen.</string>
<string name="scroll_app_bar">App-Leiste scrollen</string>
<string name="scroll_app_bar_summary">Scrollt die App-Leiste mit der URL nach oben, wenn die Webseite gescrollt wird.</string>
<string name="bottom_app_bar">Untere Anwendungs-Leiste</string>
<string name="unknown_size">Tamaño desconocido</string>
<string name="invalid_url">URL inválida</string>
<string name="saving_file">Guardando archivo:</string>
- <string name="file_saved">Archivo guardado:</string>
<string name="processing_image">Procesando imagen… :</string>
- <string name="image_saved">Imagen guardada:</string>
- <string name="error_saving_file">Error guardando archivo: \u0020 %1$s</string>
<!-- View Source. -->
<string name="request_headers">Cabeceras de solicitud</string>
<string name="swipe_to_refresh">Deslizar para actualizar</string>
<string name="swipe_to_refresh_summary">Algunas webs no funcionan bien si la opción deslizar para actualizar está habilitada.</string>
<string name="download_with_external_app">Descargar con una app externa</string>
- <string name="download_with_external_app_summary">Use una app externa para descargar archivos.</string>
<string name="scroll_app_bar">Desplazar la barra de aplicaciones</string>
<string name="scroll_app_bar_summary">Desplazar la barra de aplicaciones desde la parte superior de la pantalla cuando el WebView se desplaza hacia abajo.</string>
<string name="bottom_app_bar">Barra inferior de la app</string>
<string name="unknown_size">taille inconnue</string>
<string name="invalid_url">URL invalide</string>
<string name="saving_file">Enregistrement du fichier :</string>
- <string name="file_saved">Fichier enregistré :</string>
<string name="processing_image">Traitement de l\'image… :</string>
- <string name="image_saved">Image sauvegardée :</string>
- <string name="error_saving_file">Erreur lors de l\'enregistrement du fichier : \u0020 %1$s</string>
<!-- View Source. -->
<string name="request_headers">En-tête de la requête</string>
<string name="swipe_to_refresh">Glisser pour rafraîchir</string>
<string name="swipe_to_refresh_summary">Certains sites Web ne fonctionnent pas bien lorsque "Glisser pour rafraîchir" est activé.</string>
<string name="download_with_external_app">Téléchargement avec une app externe</string>
- <string name="download_with_external_app_summary">Utiliser une application externe pour télécharger des fichiers.</string>
<string name="bottom_app_bar">Barre d\'application en bas</string>
<string name="bottom_app_bar_summary">Déplacer la barre d\'application vers le bas de l\'écran. La modification de ce paramètre entraîne le redémarrage de Privacy Browser.</string>
<string name="scroll_app_bar">Défilement barre d\'applications</string>
<string name="unknown_size">Dimensione sconosciuta</string>
<string name="invalid_url">URL non valida</string>
<string name="saving_file">Salvataggio file:</string>
- <string name="file_saved">File salvato:</string>
<string name="processing_image">Creazione immagine… :</string>
- <string name="image_saved">Immagine salvata:</string>
- <string name="error_saving_file">Errore salvataggio file: \u0020 %1$s</string>
<!-- View Source. -->
<string name="request_headers">Richiesta Intestazioni</string>
<string name="swipe_to_refresh">Swipe per aggiornare</string>
<string name="swipe_to_refresh_summary">Alcuni siti non funzionano correttamente se questa opzione è abilitata.</string>
<string name="download_with_external_app">Scarica con una applicazione esterna</string>
- <string name="download_with_external_app_summary">Utilizza una applicazione esterna per scaricare i file.</string>
<string name="scroll_app_bar">Permetti lo scrolling della barra dell\'applicazione</string>
<string name="scroll_app_bar_summary">Permette lo scorrere della barra dell\'applicazione dalla parte alta dello schermo quando si effettua lo scrolling.</string>
<string name="bottom_app_bar">Barra dell\'app in basso</string>
<string name="unknown_size">tamanho desconhecido</string>
<string name="invalid_url">URL inválida</string>
<string name="saving_file">Salvando file:</string>
- <string name="file_saved">Arquivo Salvo:</string>
<string name="processing_image">Processando imagem… :</string>
- <string name="image_saved">Image saved:</string>
- <string name="error_saving_file">Erro ao salvar o arquivo: \u0020 %1$s</string>
<!-- View Source. -->
<string name="request_headers">Solicitar cabeçalhos</string>
<string name="swipe_to_refresh">Deslize para atualizar</string>
<string name="swipe_to_refresh_summary">Alguns sites não funcionam bem se deslizar para atualizar estiver habilitado.</string>
<string name="download_with_external_app">Download com aplicativo externo</string>
- <string name="download_with_external_app_summary">Usar um aplicativo externo para baixar arquivos.</string>
<string name="scroll_app_bar">Role a barra de aplicativos</string>
<string name="scroll_app_bar_summary">Role a barra de aplicativos para fora da parte superior da tela quando o WebView rola para baixo.</string>
<string name="bottom_app_bar">Barra de aplicativos inferior</string>
<string name="unknown_size">неизвестный размер</string>
<string name="invalid_url">неправильный URL</string>
<string name="saving_file">Сохранение файла:</string>
- <string name="file_saved">Файл сохранен:</string>
<string name="processing_image">Обработка изображения… :</string>
- <string name="image_saved">Изображение сохранено:</string>
- <string name="error_saving_file">Ошибка сохранения файла: \u0020 %1$s</string>
<!-- View Source. -->
<string name="request_headers">Заголовки запроса</string>
<string name="swipe_to_refresh">Потянуть для обновления</string>
<string name="swipe_to_refresh_summary">Некоторые веб-сайты могут работать некорректно при включении данной опции.</string>
<string name="download_with_external_app">Загрузка во внешнем приложении</string>
- <string name="download_with_external_app_summary">Использовать внешнее приложение для загрузки файлов.</string>
<string name="scroll_app_bar">Прокручивать панель приложения</string>
<string name="scroll_app_bar_summary">Прокручивает панель приложения вверху экрана при прокрутке WebView вниз.</string>
<string name="bottom_app_bar">Нижняя панель приложения</string>
<string name="unknown_size">unknown size</string>
<string name="invalid_url">invalid URL</string>
<string name="saving_file">Saving file:</string>
- <string name="file_saved">File saved:</string>
+ <string name="saved">%1$s saved.</string>
<string name="processing_image">Processing image… :</string>
- <string name="image_saved">Image saved:</string>
- <string name="error_saving_file">Error saving file: \u0020 %1$s</string>
+ <string name="error_saving_file">Error saving %1$s: \u0020 %2$s</string> -->
+ <string name="unknown_error">Unknown error</string>
<!-- View Source. -->
<string name="request_headers">Request Headers</string>
<string name="clear">Clear</string>
<string name="logcat_copied">Logcat copied.</string>
<string name="privacy_browser_logcat_txt">Privacy Browser %1$s Logcat.txt</string>
- <string name="saved">%1$s saved.</string>
<string name="error_saving_logcat">Error saving logcat: \u0020 %1$s</string>
<!-- Guide. -->
<string name="swipe_to_refresh">Swipe to refresh</string>
<string name="swipe_to_refresh_summary">Some websites don’t work well if swipe to refresh is enabled.</string>
<string name="download_with_external_app">Download with external app</string>
- <string name="download_with_external_app_summary">Use an external app to download files.</string>
+ <string name="download_with_external_app_summary">External apps will not honor Privacy Browser’s proxy settings and will not have access to cookies
+ (meaning that it is unlikely that files downloaded from sites that require a login will work).</string>
<string name="scroll_app_bar">Scroll the app bar</string>
<string name="scroll_app_bar_summary">Scroll the app bar off the top of the screen when the WebView scrolls down.</string>
<string name="bottom_app_bar">Bottom app bar</string>