2017-04-05 2 views
0

Ours는 사용자가 업로드 한 비디오 포털 사이트입니다. 최근에 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(); 
        } 

을 배치 한 것을 코드입니다. 그러나 동영상 URL을 공유해야하며 사용자가 URL을 탭하면 사용자는 앱으로 연결됩니다.

어떻게 할 수 있습니까?

답변

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