I want to make tweet/share buttons for gamers. They will make them able to write some tweets or share the gained score in the wall.
I found this code:
String shareBody = "Share text";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Test"));
This code is quite good.
For the Twitter app, the text is sent correctly. ("Share text")
But it doesn't work for the facebook app.
Where is the error?
Thanks in advance!
You have no error - it's simply impossible.
Facebook is limiting the "share via intent" to display only the hyperlinks if exists. you can't display any regular text.
The only way to do that is to make a full facebook connect (Facebook's Android SDK) and ask post-to-wall permissions from user.
Related
In our Android application, I am using Intent to share a URL as text with apps like Email apps, SMS app. I want to add an additional text as a signature (which should be appended to the original text) only in case of choosing Email and not in case of choosing SMS. Please suggest, how I can use different text for Email and SMS? Here is the sample code I am using for simply sharing.
String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share using"));
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "SHARE BODY https://www.messenger.com");
startActivity(Intent.createChooser(sharingIntent, "HUO"));
This text will be shared correctly for other apps, but messenger will only share the URL. Why? How can I fix this?
This text will be shared correctly for other apps
Some apps might support that. Apps do not have to, as what you are doing (using both EXTRA_TEXT and EXTRA_STREAM) is outside the scope of the ACTION_SEND contract. You are supposed to use either EXTRA_TEXT or EXTRA_STREAM, not both.
How can I fix this?
Get rid of EXTRA_TEXT, or get rid of EXTRA_STREAM, or live with random results from apps with your existing Intent structure.
I want to send text from my app, have copied text to clipboard using clipboard manager . Now what I want to do is to create an Intent chooser which only display chat apps like Hike, WhatsApp, sms or any other similar app.
How to do it?
Just use a SEND intent.
Similar to:
String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));
It'll show all apps, including email. WhatsApp etc. will ignore the subject, while an MMS or email will use it.
I have a simple app that will, at some point, generate a string of text that I want to share with any other app installed on the phone that can take a string of text (twitter, facebook, etc.)
Here's a sample of what I'm trying to do:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
This is from: https://developer.android.com/training/sharing/send.html#send-text-content
However, Android studio says it "cannot resolve" startActivity and suggests that I do this:
import static android.support.v4.app.ActivityCompat.startActivity;
Ok, so I do that and now startActivity() is expecting three inputs. This seems to be a new requirement because of an update. All the code examples I've seen only give it two inputs at most. The expectation is:
An activity???
The intent, which we defined
The bundle/extra options which I am leaving null
How do I satisfy the first input? Will it be possible to redirect back to my app after the sharing function is complete?
try this
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is my text");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "This is the title");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
setting title is not compulsory. then the "share using" is just a text which you can replace with anything you want. its just shows above all suggested application
I used the following code.
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT, subject);
share.putExtra(
Intent.EXTRA_TEXT,
"i have just visited http://www.google.com");
startActivity(Intent.createChooser(share,
"Share Sydneyho! with your friends via"));
When i select gmail its showing what is written in Intent.EXTRA_TEXT but when i am selecting facebook its entirely different message and i don't know from where its comes from.
please help!
I have used the following code snippet to share Message with Action_Send to other apps.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra("android.intent.extra.SUBJECT", "");
sharingIntent.putExtra("android.intent.extra.TEXT", "ABC");
startActivity(Intent.createChooser(sharingIntent, "Share using"));
And it works fine in my device(Android 2.2).
Conceptually I dont know what is different between your code and above.
But the above code works fine for me.
Got some similar posts here at stackoverflow and come to this conclusion we cant pass text
in
share.putExtra(Intent.EXTRA_TEXT,"bla bla bla");
to make it visible on facebook share page but we have to pass link to a website.