Expo mail composer sending email with attachment in android error

react-native: 0.61.5
expo: 37.0.8
“expo-print”: “~8.1.0”,
“expo-mail-composer”: “~8.1.0”,

I generate a pdf file with expo-print and get the uri by calling printToFileAsync,

const { uri } = await Print.printToFileAsync({ html })

Then I wanted to send the pdf by email through expo-mail-composer as below

await MailComposer.composeAsync({
        recipients: [email],
        subject: `${dayjs().format('YYYYMMDD')}_record`,
        isHtml: false,
        attachments: [fileUri],
      })

this working pretty well in iOS environment, but with android I get the error as:

Error: Encountered an exception while calling native method: Exception occurred while executing exported method composeAsync on module ExpoMailComposer: file:///xxx/Print/xxx.pdf exposed beyond app through ClipData.Item.getUri()

I’ve search on the forum as well as any resource I can access,
and I have tried to setup “android fileprovider” and try to send the attachment by “expo-file-system” getContentUriAsync to get the content uri but no luck

<provider
      android:name="androidx.core.content.FileProvider"
      android:authorities="xxxfileprovider"
      android:grantUriPermissions="true"
      tools:replace="android:authorities"
      android:exported="false">
      <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        tools:replace="android:resource"
        android:resource="@xml/filepaths" />
    </provider>

can anyone help me with the issue, thanks in advance :slight_smile:

Change this :
return FileProvider.getUriForFile(application, application.getPackageName() + ".provider", file);
To this:
return FileProvider.getUriForFile(application, application.getPackageName() + ".MailComposerFileProvider", file);
In this route :
node_modules/expo-mail-composer/android/src/main/java/expo/modules/mailcomposer/MailComposerModule.java and it has to be fixed.