Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share Video From Android App

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

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.

How can we do that?

like image 735
aswarth Avatar asked Apr 05 '17 07:04

aswarth


People also ask

How can I email a large video from my Android?

The best method right now on how to send large videos on android would be to use a cloud service such as Google Drive or Dropbox. Simply upload the file there and use the sharing link to send the file to your coworkers, friends, or family.


2 Answers

This worked with me. Give a try!

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();
like image 158
Hamzeh Soboh Avatar answered Nov 09 '22 07:11

Hamzeh Soboh


You should download video first. Then you can share with using 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");
like image 43
iravul Avatar answered Nov 09 '22 07:11

iravul