从我的应用程序分享whatsapp上的视频

时间:2017-09-07 13:10:00

标签: android video share

我想分享视频,当用户想要分享该视频时,我有相关的链接及其在应用程序中下载,
现在视频不在whatsapp上共享我现在不知道如何,这是我的代码
我尝试但没有工作。

 Intent videoshare = new Intent(Intent.ACTION_SEND);
    videoshare.setType("*/*");


    videoshare.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.DIRECTORY_DOWNLOADS+"/"+title));

        videoshare.setPackage("com.whatsapp");
        startActivity(Intent.createChooser(videoshare, "Share video")); 

2 个答案:

答案 0 :(得分:3)

我终于找到了解决方案就在这里

public void shareVideoWhatsApp() {


        Uri uri = Uri.fromFile(v);
        Intent videoshare = new Intent(Intent.ACTION_SEND);
        videoshare.setType("*/*");
        videoshare.setPackage("com.whatsapp");
        videoshare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        videoshare.putExtra(Intent.EXTRA_STREAM,uri);

        startActivity(videoshare);

    } 

答案 1 :(得分:0)

public void shareVideo(String pkgname, String appname) {
  String path = null;
  try {
    path = MediaStore.Images.Media.insertImage(getContentResolver(),
    arrImagePath.get(slidePager.getCurrentItem()), "Title", null);
  } catch (FileNotFoundException e1) {
    e1.printStackTrace();
  }
  Uri uri = Uri.parse(path);
  Intent share = new Intent(Intent.ACTION_SEND);
  share.setPackage(pkgname);
  share.putExtra(Intent.EXTRA_STREAM, uri);
  share.setType("Video/*");
  share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  startActivity(Intent.createChooser(share, "Share image File");
}

shareVideo(" com.whatsapp"," Whatsapp");