Я пытаюсь прикрепить pdf-файл из папки Downloads внутреннего хранилища к приложению Gmail с помощью Intent. Но это дает мне ошибку Unable to attach the file
. Я использую FileProvider для получения файла папки загрузок. Вот код, который я написал.
MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File pdfDirectory = new File(Environment.getExternalStorageDirectory(), "Download");
File pdfFile = new File(pdfDirectory, "fileName.pdf");
Uri pdfFileContentUri = FileProvider.getUriForFile(this, APPLICATION_ID + ".fileprovider", pdfFile);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_STREAM, pdfFileContentUri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
AndroidManifests
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
provider_paths
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
Может кто-нибудь подсказать, как решить эту проблему?