Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Cómo resolver Uri y Path extraños e incompletos recibidos al compartir directamente una imagen desde la galería de Android a mi aplicación flutter

He escrito una funcionalidad en Kotlin para que la aplicación flutter comparta archivos multimedia directamente desde la galería del teléfono Android a la aplicación.

Funciona bien para muchos dispositivos que he probado como Realme 3 Pro, Oneplus 6t, Samsung m40.

Pero, para Asus Zenfone Max Pro M2 al compartir cualquier archivo multimedia recibió URI y path extraños e incompletos

Registros del código Kotlin

D/URI =====(26032): contenido://com.android.providers.downloads.documents/document/624

D/Ruta =====(26032): /documento/624

Código Kotlin

 override fun onAttachedToActivity(binding: ActivityPluginBinding) { this.binding = binding binding.addOnNewIntentListener(this) handleIntent(binding.activity.intent, true) } ---------------------------------------------------------------------- private fun handleIntent(intent: Intent, initial: Boolean) { when { (intent.type?.startsWith("text") != true) && (intent.action == Intent.ACTION_SEND || intent.action == Intent.ACTION_SEND_MULTIPLE) -> { // Sharing images or videos val value = getMediaUris(intent) if (initial) initialMedia = value latestMedia = value eventSinkMedia?.success(latestMedia?.toString()) } ... ---------------------------------------------------------------------- private fun getMediaUris(intent: Intent?): JSONArray? { if (intent == null) return null return when (intent.action) { Intent.ACTION_SEND -> { val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM) Log.d("URI =====",uri) val path = uri?.let{ FileDirectory.getPathFromUri(applicationContext, it) } ?: uri?.path Log.d("Path =====",path) if (path != null) { ...

Información del dispositivo

 Device Name: Asus Zenfone Max Pro M2 Android Version: 9 External SD card: present

¿Cómo resolver este URI y obtener una ruta adecuada con nombre de archivo y extensión?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar el complemento uri_to_file para obtener la ruta desde content://uri . Para usar, simplemente analice el uri y use toFile(uri)

 import 'package:uri_to_file/uri_to_file.dart'; try { String uriPath = 'content://com.android.providers.downloads.documents/document/624'; Uri uri = Uri.parse(uriPath); File file = await toFile(uri); } catch (e) { debugPrint(e); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!