Error: Cannot attach empty file in GMAIL app using File provider(错误:无法使用文件提供程序在 GMAIL 应用程序中附加空文件)
问题描述
我正在尝试在 gmail 应用程序中附加 pdf
文件.我已阅读
我对这一行 <files-path name="pdf_folder" path="documents/"/>
中的文件夹名称感到困惑.该文件位于 Phonedocuments
中.那么为什么是文件夹名称?
编辑 1
尝试将 setType(application/pdf)
替换为 setType("message/rfc822")
但没有奏效.有什么帮助吗?
如果可以发Zip就试试这个方法
String fileNameStor_zip = Environment.getExternalStorageDirectory() + "/";+ 文件名 + ".zip";String[] path = {你的第一个 pdf 文件路径,你的第二个 pdf 文件路径};压缩 compress = new Compress(path, fileNameStor_zip);压缩.zip();URI = Uri.parse("file://" + fileNameStor_zip);
提供您的 Gmail Intent
intent.putExtra(Intent.EXTRA_STREAM, URI);
I am trying to attach a pdf
file in gmail app. I have read this and this (applied solution) I am trying as;
public static void attachFile(Context ctx) {
String TAG = "Attach";
File documentsPath = new File(ctx.getFilesDir(), "documents");
Log.i(TAG,"documentsAbsolutePath Output");
Log.i(TAG, documentsPath.getAbsolutePath().toString());
File file = new File(documentsPath, "sample.pdf");
if ( file.exists() ) {
Toast.makeText(ctx, "Exits", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(ctx, "Not Exist", Toast.LENGTH_LONG).show();
}
Log.i(TAG,"file Output");
Log.i(TAG, file.toString());
Log.i(TAG, String.valueOf(file.length()));
Uri uri = FileProvider.getUriForFile(ctx, "com.example.fyp_awais.attachfiletest2.fileprovider", file);
Log.i(TAG,"URI Output");
Log.i(TAG,uri.toString());
Intent intent = ShareCompat.IntentBuilder.from((Activity) ctx)
.setType("application/pdf")
.setStream(uri)
.setChooserTitle("Choose bar")
.createChooserIntent()
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
ctx.startActivity(intent);
}
Outputs
documentsAbsolutePath Output
/data/data/com.example.fyp_awais.attachfiletest2/files/documents
file Output
/data/data/com.example.fyp_awais.attachfiletest2/files/documents/sample.pdf
0
URI Output
content://com.example.fyp_awais.attachfiletest2.fileprovider/pdf_folder/sample.pdf
Menifest
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.fyp_awais.attachfiletest2.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepath" />
</provider>
FilePath.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="pdf_folder" path="documents/"/>
</paths>
</PreferenceScreen
A pdf file is saved in Galaxy Core PrimePhonedocuments
. (file size: 53.7KB)
But it gives
Cannot attach empty file.
I am confused with folder-name in this line <files-path name="pdf_folder" path="documents/"/>
. The file is in the Phonedocuments
. Then why folder name?
Edit 1
Tried to replace setType(application/pdf)
with setType("message/rfc822")
But did not work. Any help?
if it's ok To send Zip then try this way
String fileNameStor_zip = Environment.getExternalStorageDirectory() + "/" + fileName + ".zip";
String[] path = { your 1st pdf File Path, your 2nd pdf File Path};
Compress compress = new Compress(path, fileNameStor_zip);
compress.zip();
URI = Uri.parse("file://" + fileNameStor_zip);
Provide your Gmail Intent
intent.putExtra(Intent.EXTRA_STREAM, URI);
这篇关于错误:无法使用文件提供程序在 GMAIL 应用程序中附加空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:错误:无法使用文件提供程序在 GMAIL 应用程序中附加空文件


- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01