How can I share a string message on twitter? I would like to let the user choose between multiple string messages and click on one to share it via Twitter.
You can tap the Tweet icon to take or upload a video to add to your thought. Below the Tweet compose box, you'll see quick selection options to add a new video. Your most recent videos from your gallery will appear as thumbnail previews for easy access. Tap the camera icon to take a video.
The Twitter for Android app is available for phones running Android OS versions 7.93. 4 and above. Note: We no longer support older versions of Twitter for Android. To experience the most up-to-date Twitter for Android experience, download the latest version in the store or visit twitter.com in your browser.
Share Tweets outside of Twitter through SMS messages, email, or a range of apps. Tap the Share icon and select a contact or app. Also, you can copy a link to the Tweet and share the link however you want.
There are a number of ways to implement this.One may be simply open up http://twitter.com and share tweets in a single intent such as..
Intent tweet = new Intent(Intent.ACTION_VIEW);
tweet.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message)));//where message is your string message
startActivity(tweet);
Or,
Intent tweet = new Intent(Intent.ACTION_SEND);
tweet.putExtra(Intent.EXTRA_TEXT, "Sample test for Twitter.");
startActivity(Intent.createChooser(share, "Share this via"));
Or,
String tweetUrl = "https://twitter.com/intent/tweet?text=WRITE YOUR MESSAGE HERE &url="
+ "https://www.google.com";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
To share via twitter I use my own custom static function in a Util class like so:
public class Util
{
public static Intent getTwitterIntent(Context ctx, String shareText)
{
Intent shareIntent;
if(doesPackageExist(ctx, "com.twitter.android"))
{
shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setClassName("com.twitter.android",
"com.twitter.android.PostActivity");
shareIntent.setType("text/*");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
return shareIntent;
}
else
{
String tweetUrl = "https://twitter.com/intent/tweet?text=" + shareText;
Uri uri = Uri.parse(tweetUrl);
shareIntent = new Intent(Intent.ACTION_VIEW, uri);
return shareIntent;
}
}
}
The advantage of this function is that if the twitter app is installed it uses that, otherwise, it uses the web based twitter page. The text that will be tweeted is passed into the function.
In your scenario, when the user has selected from a choice of messages, pass the selected message into the function. It will then give you back an Intent which you can plug into startActivity() function like so:
startActivity(Util.getTwitterIntent(context, "Text that will be tweeted"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With