我正在尝试使用Facebook V4.0.0 SDK进行图像共享。
我正在使用SharePhoto
和SharePhotoContent
课程在Facebook上分享图片。
请检查以下代码
if (ShareDialog.canShow(SharePhotoContent.class)) {
Toast.makeText(getActivity(), " text 1", Toast.LENGTH_SHORT).show();
Bitmap image = BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.ic_launcher);
SharePhoto sharePhoto = new SharePhoto.Builder().setBitmap(image).setUserGenerated(true).build();
SharePhotoContent content = new SharePhotoContent.Builder().addPhoto(sharePhoto).build();
Toast.makeText(getActivity(), " text 2", Toast.LENGTH_SHORT).show();
shareDialog.show(content);
Toast.makeText(getActivity(), " text 3", Toast.LENGTH_SHORT).show();
}
我可以成功使用内联代码在Facebook上分享视频。
if (ShareDialog.canShow(ShareVideoContent.class)) {
ShareVideo shareVideo = new ShareVideo.Builder().setLocalUrl(selectedVideo).build();
ShareVideoContent shareVideoContent = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.setContentTitle(StaticCredentials.HASH_TAG)
.setContentDescription(StaticCredentials.HASH_TAG)
.build();
shareDialog.show(shareVideoContent);
}
在分享图片时收到错误Failed to copy image
。
希望对此有任何建议。
感谢您的关心和支持。
问候。
答案 0 :(得分:0)
要发布视频,请进行内联工作..
private void shareOverFacebookVideo(Uri selectedVideo) {
if (ShareDialog.canShow(ShareVideoContent.class)) {
ShareVideo shareVideo = new ShareVideo.Builder().setLocalUrl(selectedVideo).build();
ShareVideoContent shareVideoContent = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.setRef(party_key1)
.setContentTitle(party_key1)
.setContentDescription(party_key1)
.build();
shareDialog.show(shareVideoContent);
} else {
//Toast.makeText(getActivity(), "Can't show pic upload", Toast.LENGTH_SHORT).show();
}
}
调用方法如:shareOverFacebookVideo(uri);
选择视频......
public void getVideo(final int requestcode) {
AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(getActivity());
myAlertDialog.setTitle("Upload Video Option");
myAlertDialog.setMessage("Upload video via");
myAlertDialog.setPositiveButton("Gallery",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
pickPhoto.setType("video/*");
startActivityForResult(pickPhoto, requestcode);//Here requestcode is one that needs to be used over onActivityResult method
}
});
myAlertDialog.setNegativeButton("Camera",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent takePicture = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takePicture, requestcode);
}
});
myAlertDialog.show();
}
如果有任何疑虑,请告诉我。
干杯!!
答案 1 :(得分:0)
以下作品正是如此。这是关于“SharePhoto和SharePhotoContent”的原始问题:
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.your_image_here);
SharePhoto sharePhoto = new SharePhoto.Builder().setBitmap(bitmap).build();
SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().addPhoto(sharePhoto).build();
ShareDialog shareDialog = new ShareDialog(MainActivity.this);
shareDialog.show(sharePhotoContent);
以下是相关评论和兴趣点......
@AndroidHacker或任何熟悉上述问题视频部分的人: ***您是否能够成功使用ShareVideoContent.setContentTitle方法? 无论我尝试使用这个确切的代码(直接来自SDK文档),我都无法从Android SDK中获取ShareVideoContent.setContentTitle方法(因此可以在时间轴/新闻Feed中看到) )。 我已经能够在PHP中完成这项工作并且它完美运行,所以你知道它可以完成 - 但是从Android SDK它不能正常工作...... 非常感谢你!!