Android intent share to share a video url on facebook

社会主义新天地 提交于 2020-01-24 22:44:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!