问题
On my android app, I want to share a video url on facebook, i've tried two ways. One:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, videoPathURL[position]);
shareIntent.setPackage("com.facebook.katana");
activity.startActivity(shareIntent);
This first way only share on facebook a link like text "https://..." so you can click and open a new tab on browser that will play the video.
Second:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/*");
Uri uri = Uri.parse(videoPathURL[position]);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setPackage("com.facebook.katana");
activity.startActivity(sharingIntent);
This one doesn't share anything. Anyone have an idea to solve this ? I want the video to be displayed on facebook like a video and not like an URL.
Is it possible ? Or my only option is sharing the url like so ? Please help me with this
Thanks in advance
回答1:
After several hours of trying to find out how to make it work for uploading and sharing video on facebook, youtube, instagram and whatsapp. this is the code that worked for me. Uploading recorded video from your application to social media applications
try using ContentValues when dealing with videos.
ContentValues content = new ContentValues(4);
content.put(Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis() / 1000);
content.put(Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, "your_path_to_video");
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Title");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"share:")); `
来源:https://stackoverflow.com/questions/24431974/android-intent-share-to-share-a-video-url-on-facebook