栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何通过电子邮件发送已保存的CSV文件或如何通过Android中的Google云端硬盘上传?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何通过电子邮件发送已保存的CSV文件或如何通过Android中的Google云端硬盘上传?

res / xml / provider_paths.xml中* 创建一个xml文件 *

<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android">    <!--     name is the file name     path is the root of external storage, it means here: Environment.getExternalStorageDirectory()     -->    <external-path name="scale" path="."/>    <!--    another example:  Environment.getExternalStorageDirectory() + File.separator + "temps" + "myFile.pdf"     -->    <external-path name="myFile" path="temps"/></paths>

清单* 中的应用程序标记中添加提供程序 *

<!--android:name="android.support.v4.content.FileProvider"--><provider    android:name="androidx.core.content.FileProvider"    android:authorities="your.application.package.fileprovider"    android:grantUriPermissions="true"    android:exported="false">    <meta-data        android:name="android.support.FILE_PROVIDER_PATHS"        android:resource="@xml/provider_paths" /></provider>

最后将代码更改为此:

public static void sendEmailWithAttachment(Context context) {    String filename="/scale.csv";    File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);    //Uri path = Uri.fromFile(filelocation);    Uri path = FileProvider.getUriForFile(context, "your.application.package.fileprovider", filelocation);    Intent emailIntent = new Intent(Intent.ACTION_SEND);    // set the type to 'email'    emailIntent .setType("vnd.android.cursor.dir/email");    String to[] = {"email@gmail.com"};    emailIntent .putExtra(Intent.EXTRA_EMAIL, to);    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Scale Data");    emailIntent.putExtra(Intent.EXTRA_TEXT, "This is the body");    emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);    // the attachment    emailIntent .putExtra(Intent.EXTRA_STREAM, path);    context.startActivity(Intent.createChooser(emailIntent, "Send mail..."));}

有关从android文档定义文件路径的一些提示


<files-path name="name" path="path" />

表示Context.getFilesDir()


<cache-path name="name" path="path" />

代表getCacheDir()


<external-path name="name" path="path" />

表示Environment.getExternalStorageDirectory()。


<external-cache-path name="name" path="path" />

表示Context#getExternalFilesDir(String)Context.getExternalFilesDir(null)


<external-media-path name="name" path="path" />

表示Context.getExternalCacheDir()。


阅读更多文档



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号