Android share text and image - android

I need to share text+image via Facebook, email etc. Now, I use this code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text));
//Uri path = Uri.parse("android.resource://com.android.mypackage/" + R.drawable.arrow);
Uri path = Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
intent.putExtra(Intent.EXTRA_STREAM, path );
Intent mailer = Intent.createChooser(intent, null);
startActivity(mailer);
The problem is that when I use "arrow.png", it says "Couldn't show attachment" and doesn't attach image; when I remove .png, I cannot open attached file later.
Basically, I need to attach png from drawable and some text and share it via ACTION_SEND

Try to use
Uri.fromFile(new File("android.resource://com.android.mypackage/drawable/arrow.png"));
insted of
Uri.parse("android.resource://com.android.mypackage/drawable/arrow.png");
It will work fine if file descriptor will be valid.

Related

How to send any image file to a particular whatsapp contact through Custom Url Scheme

I got success in sending text to a particular WhatsApp contact using this code
private void openWhatsApp(String mobileNumber) {
String text = "Hi";
if(whatsappInstalledOrNot("com.whatsapp")){
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("whatsapp://send?text="+text+ "&phone="+mobileNumber));
startActivity(browserIntent);
}else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Now I want to share imageFile along with the text. I got the file path but don't know how to put in that browserIntent. Please Help.
I know its too late to answer but incase any one wondering.
Here is how you can use intent to share image file on Whatsapp
Intent share = new Intent();
// If you want to share a png image only, you can do:
// setType("image/png"); OR for jpeg: setType("image/jpeg");
share.setType("image/*");
// Make sure you put example png image named myImage.png in your
// directory
String imagePath = file; // here path to your image file
File imageFileToShare = new File(imagePath);
Uri uri = Uri.fromFile(imageFileToShare);
Log.e("media", String.valueOf(uri));
share.setPackage("com.whatsapp");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(share);
PS NOTE: You cannot send image with text as I tried some but fail to achieve it but you can share image file only from above code

Android: Download File then show app chooser to open it in?

So I've been looking all around and can't seem to figure it out, or maybe because I'm inside the emulator?
Basically I'm trying to download a file, and then show a app chooser so the user can freely choose which ever app to open it in.
One thing I'm not sure about is, how do you do a wild card mime type for the intent? I mean for example the downloaded file could be shared and opened by the mail client as an attachment, so really it should support anything.
For the purpose of brevity, the download code works and downloads, so assume the download is completed and the file is in the cache directory:
Intent install = new Intent(Intent.ACTION_VIEW);
// Create intent to show chooser
Intent chooser = Intent.createChooser(install, "Open in...");
// Verify the intent will resolve to at least one activity
if (install.resolveActivity(_progressDialog.getContext().getPackageManager()) != null) {
_progressDialog.getContext().startActivity(chooser);
}
Am I doing anything wrong?
I believe you need to provide the mime type as well e.g. with
intent.setDataAndType(Uri, mimetype);
where mimetype is like "text/plain". You can extract it from file extension, header using special method or lookup table (I don't recall how exactly it is done now).
But that's not working either at least in the emulator.
You can use this below intent to attach thefile & send email
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email#example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
finish();
return;
}
Uri uri = Uri.parse("file://" + file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));

Share intent for instagram in Android

Actually I want to share image in Instagram through intent.
I found this solution for images saved on SD card but I want to do same for image on site (link).
I tried with
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent
.putExtra(
Intent.EXTRA_STREAM,
Uri.parse("http://www.alliswell.biz/images/products/art/alliswell_signs/yellowB.jpg"));
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
But it's not working.
Edit
When I start above intent it opens my installed Instagram application and it immediately finish Instagram and toast message comes "unable to download file"
Actually it does not parse link and image respectively. What should be issue?
You should use local path to file
For example: "file:///path/to/file/image.png".
Note, that it is very important to include "file" in the path, without this part it also can show the same toast.
First of all you need to download file from that url. you may refer this code for downloading image from url:
String imageUrl = "Your_Image_Url";
if (imageUrl != null && !imageUrl.equals("")) {
String fileName = generateFileNameFromUrl(imageUrl);
String imageLocalPath = Environment.getExternalStorageDirectory()+ File.separator+"Your_App_Name"+ fileName;
if (!new File(imageLocalPath).exists()) {
ImageDownloadModel imageDownloadModel = new ImageDownloadModel();
imageDownloadModel.setImageLocalPath(imageLocalPath);
imageDownloadModel.setImageUrl(imageUrl);
imageDownloadModels.add(imageDownloadModel);
}
ImageLoadAsynkTask imageLoadAsynkTask = new ImageLoadAsynkTask(new ImageDownloadDelegate(), imageDownloadModels, albumDir, activity);
imageLoadAsynkTask.execute();
and then use uri for that image for sharing it on instagram:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageLocalPath));
shareIntent.setPackage("com.instagram.android");
activity.startActivity(shareIntent);

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

Android ACTION_SEND_MULTIPLE with video and text

I'm trying to use the ACTION_SEND_MULTIPLE intent to share at the same time a video file and a text.
Now, this works in GMAIL (video in the attachments and text in the body of the mail), however I want to do the same in Whatsapp too, but it doesn't appear in the list of apps of the intent.
My code is the next:
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Descarga la app en...");
ArrayList<Uri> contenidos = new ArrayList<Uri>();
File file = new File(Environment
.getExternalStorageDirectory()
.getAbsolutePath()
+ "/Talking/"
+ nombreVideo
+ ".3gp");
Uri screenshotUri = Uri.fromFile(file);
contenidos.add(screenshotUri);
//sharingIntent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, contenidos);
sharingIntent.setType("video/3gpp");
startActivity(Intent.createChooser(sharingIntent, "Share video using"));
Thanks for your help.
Now your code gonna work due the new updates to whatsapp, before this didn't accept this kind of intent (ACTION_SEND_MULTIPLE) because it accepts only one file at a time.
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
shareIntent.setType("image/png");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.parse("file:///mnt/sdcard/UserImages/"+ ParseUser.getCurrentUser().getObjectId() + ".png"));
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Hello test");
startActivity(Intent.createChooser(shareIntent,"Share"));
This probably means Whatsapp does not support this kind of intent (ACTION_SEND_MULTIPLE).

Categories

Resources