@@ -120,6 +120,7 @@ class MainActivity : ComponentActivity() {
120120 }
121121 enableEdgeToEdge()
122122 setContent {
123+ val logger = appContainer.logger
123124 val context = LocalContext .current
124125 val currentScreen by viewModel.currentScreen.collectAsStateWithLifecycle()
125126 val liveAnalysisState by cameraViewModel.liveAnalysisState.collectAsStateWithLifecycle()
@@ -164,7 +165,7 @@ class MainActivity : ComponentActivity() {
164165 navigation = navigation,
165166 onClearScan = { viewModel.startNewDocument() },
166167 recentDocuments = recentDocs,
167- onOpenPdf = { fileUri -> openUri(fileUri, ExportFormat .PDF .mimeType) }
168+ onOpenPdf = { fileUri -> openUri(fileUri, ExportFormat .PDF .mimeType, logger ) }
168169 )
169170 }
170171 is Screen .Main .Camera -> {
@@ -210,7 +211,7 @@ class MainActivity : ComponentActivity() {
210211 setFilename = exportViewModel::setFilename,
211212 share = { exportViewModel.onShareClicked() },
212213 save = { exportViewModel.onSaveClicked() },
213- open = { item -> openUri(item.uri, item.format.mimeType) },
214+ open = { item -> openUri(item.uri, item.format.mimeType, logger ) },
214215 ),
215216 onCloseScan = {
216217 exportViewModel.resetFilename()
@@ -236,7 +237,7 @@ class MainActivity : ComponentActivity() {
236237 LibrariesScreen (onBack = navigation.back)
237238 }
238239 is Screen .Overlay .Settings -> {
239- SettingsScreenWrapper (settingsViewModel, navigation, appContainer. logger)
240+ SettingsScreenWrapper (settingsViewModel, navigation, logger)
240241 }
241242 }
242243 }
@@ -428,7 +429,7 @@ class MainActivity : ComponentActivity() {
428429 }
429430 }
430431
431- private fun openUri (fileUri : Uri ? , mimeType : String ) {
432+ private fun openUri (fileUri : Uri ? , mimeType : String , logger : FileLogger ) {
432433 if (fileUri == null ) return
433434 val uriToOpen: Uri =
434435 if (fileUri.scheme == ContentResolver .SCHEME_CONTENT ) {
@@ -446,6 +447,11 @@ class MainActivity : ComponentActivity() {
446447 }
447448 try {
448449 startActivity(chooser)
450+ } catch (e: SecurityException ) {
451+ val errorMessage =
452+ " Failed to open URI, scheme=${uriToOpen.scheme} , authority=${uriToOpen.authority} "
453+ logger.e(" OpenUri" , errorMessage, e)
454+ throw OpenUriException (errorMessage, e)
449455 } catch (_: ActivityNotFoundException ) {
450456 showToast(getString(R .string.error_no_app))
451457 }
@@ -485,3 +491,4 @@ class MainActivity : ComponentActivity() {
485491 )
486492}
487493
494+ class OpenUriException (message : String , cause : Throwable ) : RuntimeException(message, cause)
0 commit comments