分享附件到-手机短信,手机邮箱(系统应用),//一般是通过包名去指定发送到哪个应用,所以我们这里的原理其实也是一样 //但是有些国产手机比如联想华为他们会更改这个应用的包名导致分享crash //以及Android 7.0对于uri的转换有一定的额限制,必须要申请权限
/**
* 发送邮件
*/
private void sendMail(String emailUrl) {
Intent intent = new Intent(Intent.ACTION_SEND);
String a = "file://" + emailUrl;
File f;
try {
f = new File(emailUrl);
} catch (Exception o) {
Dog.e("分享的视频生成文件失败");
return;
}
if (mShareBean != null) {
if (mShareBean.getPlatform() == PLATFORM_CODE_EMAIL) {
if (!TextUtils.isEmpty(mShareBean.getTitle())) {
intent.putExtra(Intent.EXTRA_SUBJECT, mShareBean.getContent());
}
if (!TextUtils.isEmpty(mShareBean.getContent())) {
intent.putExtra(Intent.EXTRA_TEXT, mShareBean.getTitle());
}
}
}
// 解决7.0分享失败的问题
Uri uri;
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(getActivity(), "com.meitu.overseamv.community.provider", f);
} else {
uri = Uri.fromFile(f);
}
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("video/*");
intent.setPackage("com.android.email");
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
} else {
MTToast.show(getString(R.string.community_share_sorry_no_email));
}
}
/**
* 发短信
*/
private void sendSMS(String webUrl) {
String smsBody = "";
File f;
try {
f = new File(webUrl);
} catch (Exception o) {
Dog.e("分享的视频生成文件失败");
return;
}
// String a = "file://" + webUrl;
Intent intent = new Intent(Intent.ACTION_SEND);
if (mShareBean != null) {
if (mShareBean.getPlatform() == PLATFORM_CODE_TEXT_MESSAGE) {
if (!TextUtils.isEmpty(mShareBean.getContent())) {
smsBody = smsBody + mShareBean.getContent();
}
}
}
// sendIntent.putExtra("address", "123456"); // 电话号码,这行去掉的话,默认就没有电话
// 短信内容
intent.setData(Uri.parse("mmsto:"));
intent.putExtra("sms_body", smsBody);
// 解决android7.0uri解析失败问题
Uri uri;
if (Build.VERSION.SDK_INT >= 24) {
uri = FileProvider.getUriForFile(getActivity(), "com.meitu.overseamv.community.provider", f);
} else {
uri = Uri.fromFile(f);
}
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("video/*");
intent.setPackage("com.android.mms");
// 联想改变了他收发短信的包名,所以需要加这个
if (DeviceUtils.getDeviceBrand().equals("Lenovo")) {
intent.setPackage("com.lenovo.ideafriend");
}
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(intent, 3);
} else {
MTToast.show(getString(R.string.community_share_sorry_no_message));
}
}