Я объявил FilecontentProvider в элементе приложения моего манифеста < /p>
Код: Выделить всё
android:authorities="com.my_app.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
Код: Выделить всё
< /code>
Я строю намерение и передаю его в соответствии с: < /p>
final Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{ "support@my_app.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Some Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Some content");
final File logsFolder = new File(context.getFilesDir(), "logs");
final File logsFile = new File(logsFolder, "Application.log")
final Uri contentUri = FileProvider.getUriForFile(context, "com.my_app.fileprovider", logFile);
Log.w(TAG, "Sending this log content: " + contentUri);
intent.putExtra(Intent.EXTRA_STREAM, contentUri));
intent.addFlags((Intent.FLAG_GRANT_READ_URI_PERMISSION));
startActivity(Intent.createChooser(intent, "Contact Us"));
< /code>
Это открывает выборщик, в котором Gmail является опцией, и при выборе Gmail я получаю подготовленную электронную почту с темой, контентом и т. Д., Но нет прикрепленного файла. < /p>
Заглядывает на logcat, я вижу эти ошибки (которые появляются после запуска chooserintent: < /p>
E Failed to find provider info for com.my_app.fileprovider
E ComposeActivity: Error adding attachment [CONTEXT android_log_tag="ComposeActivity" ]
hea: FileNotFoundException when openAssetFileDescriptor.
at gzz.e(PG:565)
at hsu.L(PG:182)
...
Caused by: java.io.FileNotFoundException: No content provider: content://com.my_app.fileprovider/logs/application.log
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2029)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1858)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1773)
at lky.y(PG:10)
at gzz.e(PG:452)
...
Что я делаю не так?>
Подробнее здесь: https://stackoverflow.com/questions/797 ... ail-in-gma
Мобильная версия