10M以下,建议进制算法为*1000以避免1024发生分享错误
将文件变成二进制数组,然后塞进去就OK了,我这边是直接传入的base64码省略了部分步骤
qq分享类似,不过是用intent来的
只能分享本地文件,我这边是js传的,可以将文件存到本地然后分享
File shareFileDir = StorageUtils.getExternalFileDirectory(activity.getApplicationContext(), StaticFinalUtil.SHARE_MEDIA);
File shareFile = new File(shareFileDir, shareMediaNew.title.concat(".").concat(shareMediaNew.fileType));
if (shareFile.exists()) {
Intent qqIntent = new Intent(Intent.ACTION_SEND);
Uri shareFileUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//兼容7.0
shareFileUri = FileProvider.getUriForFile(activity.getApplicationContext(), "com.DaTong.InsuranceForAndroid.fileprovider", shareFile);
//添加权限 这一句表示对目标应用临时授权该Uri所代表的文件
qqIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
qqIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}else {
shareFileUri = Uri.fromFile(shareFile);
}
qqIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
qqIntent.setType(getMimeType(shareFile.getPath()));
qqIntent.setClassName("com.tencent.mobileqq", "com.tencent.mobileqq.activity.JumpActivity");
qqIntent.putExtra(Intent.EXTRA_STREAM, shareFileUri);
activity.startActivity(qqIntent);
return;
}