Bom dia a todos
Na hora de abrir o arquivo em outro app com o file provider, quando é imagem vai normal, mas quando é outro tipo de arquivo, como áudio e pdf, no meu emulador (android 31) ele abre uma imagem aleatória e aparece essa mensagem mensagem no logcat:
Failed to ensure /data/system/shared_prefs: mkdir failed: EACCES (Permission denied)
Add DisplayResolveInfo component: ComponentInfo{com.google.android.apps.photos/com.google.android.apps.photos.pager.HostPhotoPagerActivity}, intent component: ComponentInfo{com.google.android.apps.photos/com.google.android.apps.photos.pager.HostPhotoPagerActivity}
START u0 {act=android.intent.action.VIEW dat=content://com.alura.concord.fileprovider/myFiles/Emoji 9 Marshmallow Yellow.png typ=image/png flg=0x3000001 cmp=com.google.android.apps.photos/.pager.HostPhotoPagerActivity} from uid 10160
Enquanto no meu celular(android 32), ele crasha e aparece essa mensagem:
Sending non-protected broadcast miui.intent.action.KEYCODE_EXTERNAL from system 1654:system/1000 pkg android
java.lang.Throwable
at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:13186)
outra mensagem:
supportMiPlayAudio
android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{com.milink.service/com.miui.miplay.audio.service.CoreService}
at android.app.ApplicationPackageManager.getServiceInfo(ApplicationPackageManager.java:562)
at com.miui.miplay.audio.a.g.a(Unknown Source:20)
O que poderia estar causando esse tipo de bug?
Ps: a pasta onde está armazenada os arquivos está correta, o arquivo existe e consigo abrir normalmente (não está corrompido). E to usando a versão 34 do android no projeto
Vou deixar o código do Android Manifest abaixo:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<application
android:name=".ConcordApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Concord"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.Concord"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.alura.concord.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>
</manifest>
arquivo xml do filepaths
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="myFiles" path="temp/"/>
</paths>
O fileutils:
package com.alura.concord.media
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.webkit.MimeTypeMap
import androidx.core.content.FileProvider
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import okio.use
import java.io.File
import java.io.InputStream
fun Context.openWith(mediaLink: String) {
val file = File(mediaLink)
val fileExtension = MimeTypeMap.getFileExtensionFromUrl(Uri.encode(file.path))
val fileMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension) ?: "*/*"
val contentUri: Uri = FileProvider.getUriForFile(
this,
"com.alura.concord.fileprovider",
file,
)
val shareIntent = Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(contentUri, fileMimeType)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}
startActivity(Intent.createChooser(shareIntent, "Abrir com"))
}