Prevent exception causing crash if no Activity is available to create document

This commit is contained in:
Sylvain Berfini 2025-07-26 11:44:00 +02:00
parent 865216d717
commit b3ac16052f
3 changed files with 27 additions and 14 deletions

View file

@ -1,5 +1,6 @@
package org.linphone.ui.fileviewer
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.util.DisplayMetrics
@ -127,23 +128,13 @@ class FileViewerActivity : GenericActivity() {
viewModel.exportPlainTextFileEvent.observe(this) {
it.consume { name ->
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/plain"
putExtra(Intent.EXTRA_TITLE, name)
}
startActivityForResult(intent, EXPORT_FILE_AS_DOCUMENT)
exportFile(name, "text/plain")
}
}
viewModel.exportPdfEvent.observe(this) {
it.consume { name ->
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/pdf"
putExtra(Intent.EXTRA_TITLE, name)
}
startActivityForResult(intent, EXPORT_FILE_AS_DOCUMENT)
exportFile(name, "application/pdf")
}
}
}
@ -212,4 +203,17 @@ class FileViewerActivity : GenericActivity() {
}
}
}
private fun exportFile(name: String, mimeType: String) {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = mimeType
putExtra(Intent.EXTRA_TITLE, name)
}
try {
startActivityForResult(intent, EXPORT_FILE_AS_DOCUMENT)
} catch (exception: ActivityNotFoundException) {
Log.e("$TAG No activity found to handle intent ACTION_CREATE_DOCUMENT: $exception")
}
}
}

View file

@ -1553,6 +1553,10 @@ open class ConversationFragment : SlidingPaneChildFragment() {
type = mime
putExtra(Intent.EXTRA_TITLE, name)
}
startActivityForResult(intent, EXPORT_FILE_AS_DOCUMENT)
try {
startActivityForResult(intent, EXPORT_FILE_AS_DOCUMENT)
} catch (exception: ActivityNotFoundException) {
Log.e("$TAG No activity found to handle intent ACTION_CREATE_DOCUMENT: $exception")
}
}
}

View file

@ -19,6 +19,7 @@
*/
package org.linphone.ui.main.sso.fragment
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
@ -75,7 +76,11 @@ class SingleSignOnFragment : GenericMainFragment() {
viewModel.startAuthIntentEvent.observe(viewLifecycleOwner) {
it.consume { intent ->
Log.i("$TAG Starting auth intent activity")
startActivityForResult(intent, ACTIVITY_RESULT_ID)
try {
startActivityForResult(intent, ACTIVITY_RESULT_ID)
} catch (exception: ActivityNotFoundException) {
Log.e("$TAG No activity found to handle intent: $exception")
}
}
}