错误:无法使用文件提供程序在GMAIL应用中添加空文件 [英] Error: Cannot attach empty file in GMAIL app using File provider

查看:161
本文介绍了错误:无法使用文件提供程序在GMAIL应用中添加空文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在gmail应用程序中附加 pdf 文件。我已阅读



我对这行文件夹名称感到困惑< files-path name =pdf_folderpath =documents //> 。该文件位于 \Phone\documents 中。然后为什么选择文件夹名称?

编辑1

试图用 setType(message / rfc822)替换 setType(application / pdf)但没有奏效。任何帮助?

解决方案

如果没关系发送Zip然后尝试这种方式



String fileNameStor_zip = Environment.getExternalStorageDirectory()+/+ fileName +.zip;

String [] path = {your 1st pdf File Path,你的第二个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 Prime\Phone\documents. (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 \Phone\documents. 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应用中添加空文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆