Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Why FileProvider not working with Broadcast?

I using FileProvider to generate an uri, then I want to pass it to BroadcastReceiver in another App, but I only get Exception of "Permission Denial: opening provider", how can I fix it?

There's two app: Sender & Receiver, then Sender want to share a file to Receiver, but Receiver don't need an UI, it process file in background, so I use Broadcast rather than Activity to do that. But I only get "Permission Denial"

Sender

Manifest
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="com.sender"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_path_config"/>
</provider>

file_path_config.xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path name="external" path="."/>
</paths>
sendBroadcast

var intent = Intent().apply {
    action = "com.action"
    component = ComponentName(
        "com.receiver",
        "com.receiver.MyReceiver"
    )
}

intent.data = FileProvider.getUriForFile(
    this,
    "com.sender",
    File("/storage/emulated/0/Cmd/zxz")
)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)

grantUriPermission("com.receiver", intent.data, Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)

sendBroadcast(intent)

Receiver

Manifest

<receiver
    android:name=".MyReceiver"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="com.action"/>
        <data
            android:mimeType="*/*"
            android:scheme="content"/>
    </intent-filter>
</receiver>

MyReceiver

override fun onReceive(context: Context, intent: Intent) {
    intent.data?.apply {
        val inputStream = context.contentResolver.openInputStream(this)
        Log.i(TAG, "onReceive: $inputStream")
        inputStream?.close()
    }
}

I try it many times, but only get Caused by: java.lang.SecurityException: Permission Denial: opening provider androidx.core.content.FileProvider from ProcessRecord and then crash.

But when I using Activity instead of Broadcast, it work fine.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

FileProvider documentation mentions that the lifetime of the permission is bound to the lifetime of the receiving Activity or Service. It says nothing about Broadcast receivers. So I suppose they cannot manage such intents without gettting this SecurityException.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda