I have a video file path and want to share the video on social media, but unable to share the video. I am trying following code in Android Studio 2.2, but it's not working.
Code snippet :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button shareBtn = (Button) findViewById(R.id.sharebutton);
shareBtn .setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
File f = new File("/sdcard/VID_20161201123613.mp4");
Uri uriPath = Uri.parse(f.getPath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Text");
shareIntent.putExtra(Intent.EXTRA_STREAM, uriPath);
shareIntent.setType("video/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
}
}
);
}