从Android App分享视频
问题描述:
我们是一个视频托管门户,用户可以根据他们的视图上传和获取他们的视频。我们最近推出了一款Android应用,并试图将Share按钮集成到每个视频中。下面是代码我们已经把从Android App分享视频
Intent intent = new Intent();
try {
URL url = new URL("https://www.clipsnow.com/videos/images/thumbnails/230/10493.jpg");
Bitmap image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_SEND);
intent.setData(Uri.parse("https://www.clipsnow.com"));
intent.putExtra(Intent.EXTRA_TEXT,msg);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, getImageUri(v.getContext(), image));
intent.setType("image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
v.getContext().startActivity(Intent.createChooser(intent, "Share Video"));
} catch (Exception e) {
e.printStackTrace();
}
当我们分享任何与此视频中,只有缩略图得到与视频标题一起分享。但是,我们需要将视频网址分享,并且当用户点击该网址时,用户将被带到我们的应用。
我们该怎么做?
答
你应该首先下载视频。然后你可以使用ACTION_SEND进行分享。
String path = ""; //should be local path of downloaded video
ContentValues content = new ContentValues(4);
content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
System.currentTimeMillis()/1000);
content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
content.put(MediaStore.Video.Media.DATA, path);
ContentResolver resolver = getApplicationContext().getContentResolver();
Uri uri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, content);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Hey this is the video subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Hey this is the video text");
sharingIntent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(sharingIntent,"Share Video");
答
这与我合作。试一下!
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("video/mp4");
File fileToShare = new File("storage/path/to/my_video.mp4");
Uri uri = Uri.fromFile(fileToShare);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "Share Video!"));
我们不希望用户将视频下载到本地存储。如果我们通过WhatsApp分享来自YouTube的任何视频,它会将缩略图,视频标题和视频URL分享给接收者。我们希望对我们的应用程序实施相同的实施。 – aswarth
@aswarth这是不同的东西。您应该创建帖子/视频详细信息页面并为其设置html标签。请检查http://stackoverflow.com/a/35785393/1923925也是这个http://stackoverflow.com/questions/19778620/provide-a-picture-for-whatsapp-link-sharing – iravul