I have created a share function inside a (@Composable)
that call Intent(Intent.ACTION_SEND)
the intent send without problem my file but the issue crash my app.
All my class and object implements Parcelable and Serialized, the problem is that I can not find the LinkedHashSet that cause the issue.
Gemini can not help me and I tried to isolate the issue without result
fun createKmlFile(context: Context, kml: String, trailName: String): File? {
try {
// crea la directory kml_files nella cache dell'app se non esiste già,
// e poi salva il file trail.kml all'interno di quella directory
val cacheDir = context.cacheDir
val kmlDirectory = File(cacheDir, "kml_files")
// Crea la directory se non esiste
if (!kmlDirectory.exists()) {
kmlDirectory.mkdirs()
}
val file = File(kmlDirectory, "$trailName.kml")
val fileWriter = FileWriter(file)
fileWriter.write(kml)
fileWriter.close()
return file
} catch (e: Exception) {
Log.e("Vagabondo", "Error creating KML file", e)
return null
}
}
fun shareTrail(kml: String, trailName: String, context: Context) {
val kmlFile = createKmlFile(context, kml, trailName)
if (kmlFile != null) {
val kmlUri = FileProvider.getUriForFile(
context,
"${context.packageName}.fileprovider",
kmlFile
)
Log.d("Vagabondo", "created kml uri: $kmlUri")
val sendIntent = Intent(Intent.ACTION_SEND).apply {
type = "application/vnd.google-earth.kml+xml"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
putExtra(EXTRA_STREAM, kmlUri)
}
launcher.launch(sendIntent)
}
}
FATAL EXCEPTION: main Process: net.xxxxxxx, PID: 10249 android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = java.util.LinkedHashSet) at android.os.Parcel.writeSerializable( Parcel. java: 2797) at android.os.Parcel.writeValue( Parcel. java: 2563) with tag AndroidRuntime
Thank you in advance to help me please!
New contributor