So I'm sharing an image from whatsapp app to my android app. However, the caption which is attached to it is not part of the intent. Is there a way I can check if my caption is part of the intent?
I've already been able to achieve sharing of image. But the caption attached to it does not come with it. Also when I print the intent type, it shows as 'image/jpeg' and I believe that because of this, the caption is not getting shared in the intent in the first place.
ImageView SharedImage;
TextView SharedText;
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
Log.d("Check Type", action + " " + type);
Uri receiveUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
SharedImage.setImageURI(null);
SharedImage.setImageURI(receiveUri);
}
You should be able to get the caption through
intent.getStringExtra(Intent.EXTRA_TEXT);
Related
Using Intent.ACTION_SEND to share plain text or image. Everything works fine, the third party apps bottom sheet opens and I choose the sms application but I am not able to pass in the contact number in the intent. If I use share.putExtra("address", "9839098390") the message body becomes blank, and without using this flag everything works fine except the number recipient field is empty.
I have tried share.putExtra("address", "smsto:9839098390") and share.putExtra("mmsto:address", "9839098390") in both these cases the recipient field is filled with "9839060055" but the message body becomes empty.
Here's the code
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_TEXT, message);
share.setType("text/plain");
if (contentUri != null && MIME_TYPE != null) {
share.putExtra(Intent.EXTRA_STREAM, contentUri);
share.setType(MIME_TYPE);
}
if(phoneContact != null && !TextUtils.isEmpty(phoneContact.getId()))
share.putExtra("address", phoneContact.getId());
share.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(Intent.createChooser(share, title));
I try to share url, pointing to some video in internet, and some text. Url and text need to be shared together, on one click to "share" button. I already know how to share video + text, when video is downloaded to Android device. But I want to share just url to video + text. So, url is actually text by itself, and I can't find way to share 2 separate texts. When I try following:
putExtra( Intent.EXTRA_TEXT, "url")
putExtra( Intent.EXTRA_TEXT, "text2")
only text2 is shared.
Here is my code:
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
type = "*/*"
putExtra(Intent.EXTRA_TEXT, "url")
putExtra(Intent.EXTRA_TEXT, "text2")
}
val shareIntent = Intent.createChooser(sendIntent, null)
startActivity(shareIntent)
Why is this happening?
You are overwriting the text with "text2", this is the reason why only that part is shared, see the corresponding method inside the Intent class:
public #NonNull Intent putExtra(String name, String value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putString(name, value);
return this;
}
How to fix this?
Just combine the URL and the text, e.g.:
putExtra(Intent.EXTRA_TEXT, "url" + "\n\n" + "your text");
I've tried several sources from Google and GitHub but didn't find any authentic source that could help me sending multiple pictures and posts automatically from my android gallery using the scheduler. Is anyone working with the Instagram API? If so, could you please give me some authentic source?
Instead of using the Instagram API, you can directly start an Intent to post an Image or Video to Instagram by opening a "Share with" dialog. This will require user interaction.
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Code example taken from https://www.instagram.com/developer/mobile-sharing/android-intents/
I want to share either an image or a video file using ACTION_SEND. So basically when the users taps on an image and selects "share image/video" it should send either the image selected or the video selected.
here is my code i am using:
if (filep != null) {
}
File sending=new File(filep);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
intent.setDataAndType(Uri.fromFile(sending),getMimeType(sending.getAbsolutePath()));
intent.putExtra(Intent.EXTRA_STREAM, sending);
startActivity(Intent.createChooser(intent , "Share"));
}
private String getMimeType(String url)
{
String parts[]=url.split("\\.");
String extension=parts[parts.length-1];
String type = null;
if (extension != null) {
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(extension);
}
return type;
So when testing, it takes me to which app i want to use to share with i.e whatsapp, Facebook, email etc. And then when selecting either one, it then says "sharing failed, please try again." I can't seem to figure out why it doesn't work. However i have the same code to display either image or video file full screen with ACTION_VIEW and that seems to work great but not with sharing.
Can anyone assist please?
EXTRA_STREAM needs to be a Uri, and you are not passing a Uri. Use Uri.fromFile() to construct a Uri.
Also, replace setDataAndType() with setType(), as ACTION_SEND does not use the data aspect of the Intent.
In my app I have it so that the user can send an email (code below).
This works, but I would like to improve it. There are 2 possibilities:
1. Currently, the url appears as a String. Can it be made to appear as a link in the email?
2. Include an image in the email (mylogo.png) and clicking on the image would go to the url
Is either of these possible?
private void sendEmail() {
final UserInfo userInfo = UserInfo.getInstance();
final String highScore = userInfo.getCumulativeScore();
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
//intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(crashLogFile)); // attach a file
// EXTRA_EMAIL is the recipient, which in this case we don't know, so leave blank and let user fill in
//intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"Extra Email"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Super Quiz High Score");
String url = "https://play.google.com/store/apps/details?id=com.devname.appname";
intent.putExtra(Intent.EXTRA_TEXT, "My high score in the Super Quiz is now " + highScore + "!\n\n" + url);
startActivity(createEmailOnlyChooserIntent(intent, "Send via email"));
}
Depends completely on the mail client that the receiver uses. If it's gmail, you're out of luck, they don't parse links.