Is there any onActivityResult or response for shareIntent in android? - android

I am creating an application where I can share a link to the applications available in the android devices and increase the share count but I am unable to get any response or onActivityResult for that intent.
For now I have just increased the counter when ever the button is clicked for sharing the link but that's not a correct way to do it.
I am using the below code to share the link
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "\n" + text + "\n\n" + "www.google.com");
shareIntent.setType("text/plain");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
mContext.startActivity(Intent.createChooser(shareIntent, "Share Link using ?"));
Any help is appreciable thank you.

Quoting #CommonsWare in #ndsmyter answer comments
The decision of what happens as part of an ACTION_SEND operation is up
to the other app (and the user), not you. ACTION_SEND is not designed
for use with startActivityForResult(), which is why you are not
getting results, and startActivityForResult() has no bearing on the
behavior of the other app.
So as you see, is not possible :(
Hope this helps!!

Related

Android - Chooser dialog for sharing -- different intents depending on application selected?

I'd like to share different information depending on the application selected by the user. For example, I'd like to send shorter text to Twitter than I do Gmail (otherwise, I go over in characters). Is there anyway to achieve this? Bonus question, is it possible to make hyperlinks via sharing via Gmail or SMS. For example, "Download here" where 'here' is a link instead of "Download by clicking the link below: http://..."
Current code:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, getTextToShare(data));
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, data.getTitle());
startActivity(Intent.createChooser(shareIntent, "Share this story"));
To find the selected share target this could be interesting for you: Branching the Android Share Intent extras depending on which method they choose to share
By using below code may helps you:
String shareText="Download <a href='[download link]'>here</a>";
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, Html.toHtml(shareText));
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, data.getTitle());
startActivity(Intent.createChooser(shareIntent, "Share this story"));
Share Url Links and Texts into Social Networks (Facebook,Twitter and linkedin)

Android Share intent - issue with Facebook

I need to share text and one image from my application via a share intent. I read this article. I thought it would be easy to create share intent. But it is not so easy, because there is a problem with sharing via Facebook.
I need to share some text and one image, which is stored in device. My first attempt looked like this:
The first try
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/img.jpg")));
shareIntent.putExtra(Intent.EXTRA_TEXT, "My custom text...");
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent, getString(R.string.label_share)));
I tried this code and in applications like Gmail, Google+, Google Keep, etc, everything works fine. But Facebook did not work fine.
There is no my text ("My custom text...") in this screenshot. So I have tried something else.
The second try
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File("/sdcard/img.jpg")));
shareIntent.putExtra(Intent.EXTRA_TEXT, "My custom text...");
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, getString(R.string.label_share)));
And the result of this is here:
There is no text and also no image in this screenshot.
I also tried to change type to image/* and */*, but it did not help. I do not know what is wrong. I just need to share some text and image via Facebook. The first try works well for other applications, but for Facebook not.
Can someone help me, please?
Your first attempt is OK, Facebook does not allow sharing text this way, they say "Pre-filling these fields erodes the authenticity of the user voice."

how to share available content in textview using share option

I have developed an application. In this application, content is coming from database. The content I am getting in my textview , I just want to share the whole content using email etc..
How can I just send i.e share my available content.
I am getting all sharing options, but I am not able to share the content coming on screen.
Please let me know if you want more info!
Kindly Help me!
Thanks in Advance!
It's very simple. You just need to put in your intent.
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"yourEmail#gmail.com"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
emailIntent.putExtra(Intent.EXTRA_STREAM,yourTextView.getText());
emailIntent.setType("text/html");
startActivity(emailIntent);
Firstly, you should obtain the text that you want to share. Secondly, you can use an intent in order to show to the user the different ways to share the content. You can use this code to achieve it:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, textFromTextView);
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent,
"Share with..."));
I think AndroidWarrior's answer will only allow you to use e-mail but It's correct.

Skype android api for message(IM) and file sending

I succeded in sending an intent to skype and calling whoever i want but now i want to be able to send IM and send files,all done in the background.Is that even possible ? I've looked over their developer page for android,it's kind of poor and doesn't say anything about this.
So,is there any way to do that ?
Thanks in advance and have a nice day !
I have almost succeeded in sending files over Skype using Intents. I am actually using one and the same intent for sending over email or skype, and I let the user choose the app they want to use to send the file. My code is:
File readF = new File(fullFileName);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/*");
intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.send_message_subject) + " " + myList.getName());
intent.putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.send_message_body));
Uri uri = FileProvider.getUriForFile(this, "my.package.fileprovider", readF);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Sending..."));
The File provider I use for sending the file is just like the one explained here: https://developer.android.com/reference/android/content/ContentProvider.html
If you like to send the file explicitly through Skype, and not let the user choose the app maybe you can use something like this:
sharingIntent.setClassName("com.twitter.android","com.twitter.android.PostActivity");
(explained here)
Why I ALMOST succeeded is that the filename is changed when sending over Skype. I haven't figured out how to fix this yet.

share image and text not working at all

I am working at sharing some info with an image from a resource. Here is the code I am using:
case R.id.menu_share:
//create the send intent
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
//set the type
shareIntent.setType("image/png");
//add a subject
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"CAR EXAMPLE");
//build the body of the message to be shared
String shareMessage = "An app...";
//add the message
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);
//add the img
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://com.car.pack/drawable/" + Integer.toString(R.drawable.log)));
//start the chooser for sharing
startActivity(Intent.createChooser(shareIntent,"Share"));
break;
The problem is that in my example I am trying to share a TEXT+IMAGE from a resource. So, when I share with GMAIl app works perfect, but with the others app wich appears in the intent occurs:
Whatsapp : Only send the image, the text not.
SMS: not appears the text and the image.
email app from mobile (sony ericcson Arc S): break the app
Facebook: only share the image, the text no.
Bluetooth: I don´t test yet
So I think that the problem was on the text... or I don´t know, if anyone can help me...
THANKS!!!
Use shareIntent.setType("*/*"); .
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
Check here for more details.

Categories

Resources