2017-04-05 55 views
0

我們是一個視頻託管門戶,用戶可以根據他們的視圖上傳和獲取他們的視頻。我們最近推出了一款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(); 
        } 

當我們分享任何與此視頻中,只有縮略圖得到與視頻標題一起分享。但是,我們需要將視頻網址分享,並且當用戶點擊該網址時,用戶將被帶到我們的應用。

我們該怎麼做?

回答

0

你應該首先下載視頻。然後你可以使用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"); 
+0

我們不希望用戶將視頻下載到本地存儲。如果我們通過WhatsApp分享來自YouTube的任何視頻,它會將縮略圖,視頻標題和視頻URL分享給接收者。我們希望對我們的應用程序實施相同的實施。 – aswarth

+0

@aswarth這是不同的東西。您應該創建帖子/視頻詳細信息頁面併爲其設置html標籤。請檢查http://stackoverflow.com/a/35785393/1923925也是這個http://stackoverflow.com/questions/19778620/provide-a-picture-for-whatsapp-link-sharing – iravul

0

這與我合作。試一下!

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!"));