In my android app i want to share a Link to my website using intent but i dont want it to be visible to other user
example i want to share "smoe website link"
But to user it should look like "Click me to see it".
I tried this but wasnt successfull it just shows the simple text and was not clickable
<string name="app_link">Click me!</string>
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra("PostID", postID);
intent.putExtra("UserID", userID);
intent.putExtra(android.content.Intent.EXTRA_TEXT,activity.getString(R.string.app_link);
activity.startActivity(Intent.createChooser(intent, "Share"));
Any help will be really appreciated.
What you want is not realistically possible right now.
EXTRA_TEXT must always be interpreted as plain text by the receiving app. You could try using EXTRA_HTML_TEXT which was added with API 16. But many apps don't support HTML and will simply use EXTRA_TEXT instead (or not show any text at all if you omit EXTRA_TEXT).
Related
The problem is I have an article that want to share to other apps, and I want to let the user to choose which app to share to. What I want to share is basically:
the title of the article
the URL of the article
the article content as HTML
the URL with some extra text (such as 'http://foo.com/article share from #FooApp')
All of these fields are optional, but I want to share at least one of them.
Such as when share via SMS or twitter, I want to set the content to part 4. when share via Facebook, I want to set 1, 2, 3 together. And when share via email, I want to set subject as 1 and message as 4.
I know (correct me if I'm wrong) every target intent receiver has it's own logic to pick up the fields it needed. So I want to provide as much information as possible and I wrote the following code:
String message = article.getURL() + " #FooApp";
Intent intent = new Intent().setData(Uri.parse(article.getURL())
.putExtra(Intent.EXTRA_SUBJECT, article.getTitle())
.putExtra(Intent.EXTRA_TEXT, message)
.putExtra(Intent.EXTRA_HTML_TEXT, article.getHTML())
.putExtra("sms_body", message)
...
.setType(HTTP.PLAIN_TEXT_TYPE);
startActivity(Intent.createChooser(intent, "Share to"));
But the problem is, it seems like a trick between setData, putExtra, setType.
For some apps appear in the chooser dialog, when I choose, the confirm share window (of that app) display nothing that I set to the intent. (for some other apps they just say failed to fetch resource)
For the putExtra part, when I add or remove some putExtra code, the target intent receivers diff a lot than I expected.
So the question is: am I doing it the wrong way? Are there some guideline for this problem?
I want to send a html mail from my application.
I know that not all mail clients allow html tags.
But I found the constant Intent.EXTRA_HTML_TEXT in the API (http://developer.android.com/reference/android/content/Intent.html#EXTRA_HTML_TEXT).
My code looks like this, but it shows always just the text and not the html formatted text whatever mail client I use:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, "Hello World");
intent.putExtra(Intent.EXTRA_HTML_TEXT, "<html><body><h1>Hello World</h1></body><html>");
intent.setType("text/html"); // intent.setType("plain/text");
startActivity(Intent.createChooser(intent, "Choose Email Client:"));
So where is the mistake?
Sorry, not a positive answer because it doesn't seem to work, at least not in a way that's really universal and reliable. Some mailers are happy with this:
String body = "<html>something</html>";
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
Note that you don't need the new EXTRA_HTML_TEXT, it works with the older one as well. If this covers all you need then you might be OK. But if you also want to address many other possible intent receivers like Facebook, Skype or even apps like Drive or Keep, unfortunately, I couldn't find a perfect solution but I'd very much like to be proven wrong.
Basically, we have three different formats:
String body = "<html>something</html>";
Spanned html = Html.fromHtml(body);
String stripped = html.toString();
and two possible recipients:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
intent.putExtra(Intent.EXTRA_HTML_TEXT, ???);
intent.putExtra(Intent.EXTRA_TEXT, ???);
I tried all possible combinations but in any of those, there will be some well known and widely used app that doesn't want to play nicely. Either we get HTML tags embedded, or no formatting, or even no text at all...
I want to share a location attached to my share intent. Is it possible?
Something like this, but adding location information:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "The status update text");
startActivity(Intent.createChooser(intent, "Dialog title text"));
Thanks.
You can put your location data as part of the text of the message, in EXTRA_TEXT.
Or, you are welcome to invent a new extra (e.g., EXTRA_LOCATION), put the location data in there, and then convince all the world's Android developers to use it where relevant when they implement activities that respond to ACTION_SEND.
But, beyond those two choices, ACTION_SEND does not support anything else related to location.
i´m trying to achieve a solution where the app ask if facebook.katana aka facebook app is installed in your android phone, if it is installed, check if the user is logged, and if it's logged send a picture with a text (better if it is to a folder), if the user is not logged go to the facebook.katana.LoginActivity and log him, after that make the procedure.
I have this working with a Web View, but i'm interested on how to do it using the app if possible, what i got so far is the uncompiled facebook.katana in this URL where i'm testing the activities:
http://xt720.ru/miui-trans/apk-decompiled/Facebook/smali/com/facebook/katana/
I also know that an image can be attached to that app, since can start the facebook app using this:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM,imageUri);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Whatever");
startActivity(Intent.createChooser(emailIntent, "Send email using"));
This method would be great for an email, but as it says it creates a chooser, but i don't want to let that option open. So i tried something like:
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
startActivity(intent);
Also you can use the ShareLinkActivity to add an extra to your intent like this:
intent.putExtra(Intent.EXTRA_TEXT, "http://www.google.com/");
The problem is that i don't see how to attach the image to the katana, neither, how to add it to a folder, or how to add it through an application, of course this is much easier via facebook API for android, but like i said that's already done, i want to make it with the facebook App, i have tried, attaching the Bundle to the app as a parcelable, with the usual way it is done in the API, but not luck, this is the snippet:
Bundle params = new Bundle();
params.putByteArray("picture", bitmapdata);
params.putString("title", url);
params.putString("message","Wathever message");
and try to send the params, also tried sending only the image, but not luck, maybe i'm not using the right class (see the uncopiled facebook.katana URL) or i´m attaching in a bad way the info, it should work somehow, cause it works for ACTION_SEND, so, anybody knows how to solve any of this problems:
Attach an image to the facebook.katana
Attach an image to the facebook.katana in a folder
Attach an image to the facebook.katana as an external app
Request the log status of the user to the facebook.katana (i think this would be automatically)
Attach the picture, title, message params to the facebook.katana.
Publish as the app that opens the facebook.katana (i.e. publishin with the WebView will show "published from X app"
hi friends i have a custom list coming from server and i want to add two share buttons for Gmail and Ymail resp. in that , its like when i click the Ymail share button it asks for username and password and then redirects me into the compose message section with message body as the link of the respective list and then i can access my contacts to send it to anyone i like.
1. please tell me how to do this??
2. is there any sdk available for Ymail/gmail
please suggest something..thanks in advance
to share text you don't pick the app you want to use. You pick the type of app you want to use. You can simply start an ACTION_SEND intent.
public void help() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
String s = getString(R.string.sharesubject);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, s);
startActivity(sendIntent);
}
(source: android.com)
How about a share action provider its brand new. my 1st app has a share action provider and it looks a little like this.
Basically you just fill up a share intent with the message and attach the intent to the share menu item.
search for share action provider example
Good Luck