【发布时间】:2019-07-05 23:22:08
【问题描述】:
我有一个 Android Studio 项目,可以选择通过 whatsapp 分享视频。
这是我的代码:
private void shareFile(File file){
String titulo = file.getName();
String path = file.getAbsolutePath();
Uri uri = Uri.parse(path);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.setType("video/*");
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
shareIntent.putExtra(android.content.Intent.EXTRA_TITLE, title);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
}
但是当我分享它时,我收到了来自 Whatsapp 的消息:此文件格式不兼容。 我不明白在它起作用之前会发生什么。
【问题讨论】:
-
Uri.fromFile()已在 Android 7.0+ 上被禁止。使用FileProvider。此外,请使用真正的 MIME 类型,而不是通配符。
标签: java android share whatsapp