Share video and save video to Gallery - android

I have video url, from which I parse to to get the uri. I try to pass the uri in share, but I don't see the video being shared.
Uri uri = Uri.parse(url);
Intent sharingIntent = new Intent(
Intent.ACTION_SEND);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM,uri
);
startActivity(sharingIntent);
Am I missing something here, or should I save the uri to external storage and then pass it?
Also I need to know how to save the video using the uri to Gallery.

use this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("video/mp4");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
startActivity(Intent.createChooser(intent, "share"));
"path" is your videos pass like /sdcard/mVideo.mp4

Intent.createChooser seems to be missing. Please see the code snippet and the link.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
The link:
http://sudarmuthu.com/blog/sharing-content-in-android-using-action_send-intent/

Related

Share pdf file via whatsapp from my app on Android

I am try to send pdf file from my app to whatsapp, and here is the code,
but something missing!!
it opens whatsapp and i can choose a contact but it says "sharing failed"!
the code
String PLACEHOLDER = "file:///android_asset/QUOT_2016_10(test).pdf";
File f = new File(PLACEHOLDER);
Uri uri = Uri.fromFile(f);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_TEXT, "hi");
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("application/pdf");
activity.startActivity(share);
I figured out the problem, and here is the answer if somebody had the same issue. The problem was that I am trying to open the pdf from the asset folder which did n't work, and if would try to open the pdf from the download folder for example, it would work. Please refer to the the code below for the final correct way:
File outputFile = new File(Environment.getExternalStoragePublicDirectory
(Environment.DIRECTORY_DOWNLOADS), "ref Number from Quotation.pdf");
Uri uri = Uri.fromFile(outputFile);
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
share.setType("application/pdf");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setPackage("com.whatsapp");
activity.startActivity(share);
File outputPath= new File(Environment.getExternalStorageDirectory() + "/MyPdf/example.pdf");//change with your path
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("application/pdf");
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(),
getPackageName() + ".fileprovider", outputPath);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
startActivity(Intent.createChooser(shareIntent, "Share it"));
It's technically wrong, what if someone has WhatsApp business or want to share file on gmail then use this...
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, _text);
shareIntent.putExtra (Intent.EXTRA_STREAM, Uri.parse(_file));
startActivity(Intent.createChooser( shareIntent, "Share"));
In this u just have to add text and file
Text u attach will become subject in gmail and if you are sharing image on WhatsApp then text will become as image caption

How to share content Image from URL and text in Android

I'm using this code to share content ( Image from URL and text ). but this is not working properly. I'm getting no error, but it's not sharing (I'm trying to share in WhatsApp and GoogleDrive).
Uri imageUri = Uri.parse("http://2805messa.8.2.f.unblog.fr/files/2008/03/elmahdia.jpg");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, post.getPost_text());
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.setType("image/jpeg");
v.getContext().startActivity(intent);
I've already seen the other related posts, but I couldn't find an answer to my question.
Add the flag : FLAG_GRANT_READ_URI_PERMISSION. Also check for internet permissions.
Modified code:
Uri imageUri = Uri.parse(path);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, post.getPost_text());
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
intent.setType("image/jpeg");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
v.getContext().startActivity(intent);

Share image using intent chooser

How can I share images using intent chooser. I have tried
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse(url));
where url is from internet
I am able to share text using the above code the image doesnt get attached.
try doing this instead i think it will work
Uri uri = Uri.fromFile(new File(filename));
share.putExtra(Intent.EXTRA_STREAM, uri);

Sharing image on facebook via Intent in eclipse

I am using the following code to share image to facebook but its not working.
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/png");
share.putExtra(Intent.EXTRA_STREAM,
Uri.parse("/sdcard/img1.png"));
startActivity(Intent.createChooser(share, "Share Image"));
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
One, it should be in this order just for readability and sensical reasons
you need to say what the error is...
NEVER hardcode the path to the image '/sdcard/img1.png' use getExternalStorageDirectory() instead

sharing video. mail going but no video in it

i want to share video from my application. It is giving option and when i select gmail. I am getting mail but there is no video in it. the code is as follow. can some one tell me what i did wrong in it ?
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
String path="/mnt/sdcard/DCIM/Camera/VID_19800115_233308.3gp";
Uri videoUri = Uri.parse(path);
sharingIntent.setType("video/*");
Log.i(TAG, "::onClick:" + "videoUri"+videoUri);
sharingIntent.putExtra(Intent.EXTRA_STREAM, videoUri);
startActivity(Intent.createChooser(sharingIntent, "Share Video using"));

Categories

Resources