share video on whatsapp from my app

2019-05-28 06:03发布

问题:

i want to Share video ,i have link of that and its downloaded in the app when user want to share that video,
now video is not shared on whatsapp i dont now how ,here is my code
which i tried but not worked.

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

回答1:

i finally found the solution is here

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

    } 


回答2:

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