I am using an image and text to share in whatsapp and other email and sms through intent.
But problem in whatsapp is, image is displaying, text too displaying but url is not displaying as link. It's displaying as normal text. You can see the below code as follows.
Uri imageUri = Uri.parse(photoFile.getAbsolutePath()); //getting image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Sharing the details.\n\n" +
"QR Code:" + QRCode + "\n" +
"Nama Retailer:" + retailerName + "\n" +
"Nama Owner:" + ownerName + "\n" +
"Nomer TRX:" + normorTrx + "\n" +
"Disclaimer" + "\n" +
"Please use the below link" + " "+
"http://116.12.2/images/disclaimer/NG20_SaTria_TC_Legal_050418_DISCLAIMER.pdf" +" "+
"for further information."
);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
if (shareIntent.resolveActivity(getPackageManager()) != null) {
startActivity(shareIntent);
} else {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "not available", Toast.LENGTH_SHORT).show();
}
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(RetailerQRCodeGenerationActivity.this, "Application not available.", Toast.LENGTH_SHORT).show();
}
When you want to share a url you generally do this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
i=intent.putExtra(Intent.EXTRA_TEXT, "http://www.url.com");
But you want to share two different type of intents, because I am seeing in your code that you are using shareIntent.setType("image/jpeg");
Two share different types of elements you need to use multiple MIME types like this:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
String[] mimeTypes = {"image/*", "text/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
For more details check: https://developer.android.com/guide/topics/providers/content-provider-basics#MIMETypeReference
Related
On Android I try to share image + text like this :
Uri imageUri = Uri.parse("android.resource://" + getPackageName()
+ "/drawable/" + "ic_launcher");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello");
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "send"));
this work fine on Whatsapp (for example) but on viber it's show only the image and skip the text :( On Instagram it's the total opposite, text is send but not the image ...
How can i do ?
Try this for viber :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setPackage("com.viber.voip");
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Message");
Checkout this answer for the Instagram part : https://stackoverflow.com/a/16299999
Hope this helps !!
This is my code
Intent sendIntent = new Intent();
Getting the image
Uri imageUri = Uri.parse(feedItemList.get(position).getImage());
Picasso.with(mContext).load(feedItem.getImage()).into(customViewHolder.imageView);
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
feedItem.getTitle() + "\n" +
"\n \n" + "See more " +
" https://play.google.com/store/apps/details?com.truth.origicheck.memeshare");
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.setType("image/png");
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sendIntent.setType("text/plain");
mContext.startActivity(sendIntent);
I need to send the image and text
In my application i need to share image/text to whatsapp. Sharing images or text is working fine. But my requirement is sharing images/text to specific recipant. For that i have mobile number. So before sharing, first of all that number is having whatsapp or not?. Then if the number having whatsapp, then bydefault select that specific number. If the number is not having whatsapp then simply redirect to whatspp. then they select the recipant and share to that recipant.
For sharing i am using the following code. This code is working fine for sharing.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
if (images.size() > 0) {
Log.e("count==", "val## " + images.size());
shareIntent
.putParcelableArrayListExtra(Intent.EXTRA_STREAM, images);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
shareIntent.putExtra(Intent.EXTRA_TEXT, title);
shareIntent.setType("text/plain");
}
shareIntent.setPackage("com.whatsapp");
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(ManageOnlineBuyLeadActivity.this,
"Whatsapp have not been installed.", Toast.LENGTH_SHORT)
.show();
}
And for sharing particular recipant i have changed the follwing lines
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
to
Uri mUri = Uri.parse("smsto:+number");
Intent shareIntent = new Intent(Intent.ACTION_SENDTO, mUri);
But it is not working. For this i googled alot. So please guide me how to do this. Is it possible to share particular recipant or not?
Thank you all..
The easiest way I know is by calling the following method (Use the String variable message to input the text you want to send via WhatAapp):
private void sendWhatsapp(String message){
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, message);
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(sendIntent);
}
}
I have a solution to send text only to a specific recipient. For sending an image to a specific recipient I am also using this.
String smsNumber = "Your specific contact No. here! ";
String msg = "Your message here!";
Uri uri = Uri.parse("http://api.whatsapp.com/send?phone="+smsNumber +"&text="+msg);
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
startActivity(intent);
} catch(Exception e) {
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
}
I want to attach amr file in attachment but i am unable to attach.
My code is as follows:
Intent emailIntent = new Intent(
Intent.ACTION_SEND);
Uri U = Uri.parse(path of amr file);
//System.out.println("uri is:" + U);
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { "" });
emailIntent.putExtra(
android.content.Intent.EXTRA_SUBJECT,
" from ..");
emailIntent.putExtra(
android.content.Intent.EXTRA_TEXT, ""
+ "\n" + "\n" + "Through application name");
emailIntent.setType("audio/rfc822");
//emailIntent.setType("audio/*");
// emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
emailIntent.putExtra(Intent.EXTRA_STREAM, U);
startActivity(Intent.createChooser(emailIntent,
""));
i have used emailIntent.setType("audio/rfc822") , emailIntent.setType("audio/*"); and emailIntent.setType("audio/amr"); but no luck
Any help will be appreciated.
have you tried using,
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
Activity Action: Deliver multiple data to someone else.
I want the user to be able to send an email from inside my android app, so I have
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
startActivity(emailIntent);
but I don't know what I need to do if I want to have 2 .png images attached to this email also.
Thanks,
Try out this one.
But for me it is only working on a real device.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file1));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.file2));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris));
startActivity(emailIntent);
Try this:
Intent iShare;
iShare = new Intent(Intent.ACTION_SEND);
iShare.setType("image/png");
//below you trying to send the images path it always doens have to be a
//image in the drawable u can get the captured image or in the gallery :)
iShare.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fn.getPath()));
i.putExtra(Intent.EXTRA_TEXT, "Username: " + usernames + "\nClinic Number: " + clnumber + "\nClinic Name: " + clname + "\nBranch: " + spnnr);
startActivity(Intent.createChooser(iShare, "Share"));
try {
startActivity(Intent.createChooser(ishare, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(secondpage.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}