我正在通过Gradle使用Facebook Android sdk 4.6.0。
在根据分享Facebook指南配置facebook之后,我正在尝试从移动目录上传视频,但在sharedialog.show调用之后,我得到了例外:"ShareVideo必须引用设备上的视频“。该异常是通过回调‘`onError(FacebookException异常)向我报告的。
/**first checking if file exist than execute code, file exits and code execute but after executing callback with exception "Share Video must reference a video that is on the device" occurs
**/ private void shareOnFacebook() {
File dir = new File(Environment.getExternalStorageDirectory(),
"directory");
File video = new File(dir, "Video.mp4");
if (video.exists()) {//if video file exist
Uri videoFileUri = Uri.parse(video.getPath());
ShareVideo sv = new ShareVideo.Builder()
.setLocalUrl(videoFileUri)
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(sv)
.build();
shareDialog.show(content); //show facebook sharing screen with video
}
}发布于 2015-10-18 15:04:15
if (!Utility.isContentUri(localUri) && !Utility.isFileUri(localUri)) {
throw new FacebookException("ShareVideo must reference a video that is on the device");}
public static boolean isContentUri(final Uri uri) {
return (uri != null) && ("content".equalsIgnoreCase(uri.getScheme()));
}
public static boolean isFileUri(final Uri uri) {
return (uri != null) && ("file".equalsIgnoreCase(uri.getScheme()));
}如您所见,正在检查uri是否有一个方案。在您的示例中,当您从video.getPath创建uri时,方案为null。您应该做的是从视频文件中创建uri:
Uri videoFileUri =Uri.fromFile(视频);
https://stackoverflow.com/questions/32905407
复制相似问题