从 Android 应用分享视频 [英] Share Video From Android App

查看:43
本文介绍了从 Android 应用分享视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是一个视频托管门户,用户可以在其中上传视频并根据他们获得的观看次数赚取收入.我们最近推出了一个 Android 应用程序,并尝试将分享"按钮集成到每个视频中.这是我们放置的代码

Ours is a video hosting portal where users can upload and earn from their videos based on the views they get. We have recently launched an Android App and trying to integrate Share button to each video. Here is the code what we have placed

 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();
                    }

当我们与此分享任何视频时,只会与视频标题一起分享缩略图.但是,我们需要共享视频 URL,当用户点击 URL 时,用户将被带到我们的应用程序.

When we share any video with this, only thumbnail image is getting shared along with the video title. But, we need the video URL will get shared and when user tap on the URL, user will be taken to our app.

我们该怎么做?

推荐答案

这对我有用.试试看!

File videoFile = new File(filePath);
Uri videoURI = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
        ? FileProvider.getUriForFile(mContext, mContext.getPackageName(), videoFile)
        : Uri.fromFile(videoFile);
ShareCompat.IntentBuilder.from(getActivity())
        .setStream(videoURI)
        .setType("video/mp4")
        .setChooserTitle("Share video...")
        .startChooser();

这篇关于从 Android 应用分享视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆