刚进南京星瑞斯的我接到了一个FitMore国外客户的项目,老外那边通讯基本靠邮件,所以掌握这一技能是挺关键的。这个功能要求:录音(转码)+发送邮件附件。涉及到的功能首先是录音,上一篇已经讲过实现录音功能全网有很多demo可以参考。而上一篇也是将wav转码成mp3了,所以这一篇就是发送邮件及发送附件了。
打开邮件代码如下:
public void sendEmail(Context context, String title, String content, String address) {
Uri uri = Uri.parse(“mailto:” + address);
Uri uriExtend=null;
Intent emailIntent = new Intent(Intent.ACTION_SEND, uri);
// 设置对方邮件地址
emailIntent.putExtra(Intent.EXTRA_EMAIL, address);
// 设置标题内容
emailIntent.putExtra(Intent.EXTRA_SUBJECT, title);
// 设置邮件文本内容
emailIntent.putExtra(Intent.EXTRA_TEXT, content);
emailIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
externalCacheDir =new File( this.getExternalCacheDir().getAbsolutePath());
if(!externalCacheDir.exists()){
externalCacheDir.mkdirs();
}
String bluePath = AudioFileFuncWav.getDiskCachePath(context)+"/"+"MYRECORDER"+".mp3";
File recordfile=new File(bluePath);
if (Build.VERSION.SDK_INT >= 24) {
uriExtend= FileProvider.getUriForFile(this, "com.beehome.cronovo.fileprovider",recordfile);
} else {
uriExtend = Uri.fromFile(recordfile);
}
emailIntent.putExtra(Intent.EXTRA_STREAM,uriExtend);
emailIntent.setType("audio/mp3");
context.startActivity(Intent.createChooser(emailIntent, "选择邮箱"));
}
这样看起来代码基本上是完成的,但忽略了重中之重的内容提供者contentProvider。
内容提供者给安卓设备上应用间提供接口。所以我们要配置一下。
1、AndroidManifest下
2、xml文件filepath下
很感谢你能够看到这里,刚入行半年的我,还有很多不会的,目前我也是在南京星瑞斯科技有限公司做安卓手表、安卓移动应用APP,期待一起交流。
行业交流:http://www.thinkrace.com.cn/index.html或者http://www.thinkrace.com.cn/index.html
个人交流:qq1287587036