0

I want to be able to share text (and later images as well) via an intent but only to the twitter application. I've tried using setClassNamehowever this just causes the application to stop. So far I have:

String message = "My Text.";
Intent sharingIntent = new Intent();
sharingIntent.setAction(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_TEXT, message);
sharingIntent.setType("text/plain");
startActivity(sharingIntent);

some of the answers I've found but aren't helping are:

How to force Share Intent to open a specific app?

Android Intent for Twitter application

lmathurin
  • 103
  • 1
  • 2
  • 6

1 Answers1

0

Try this

String url = "http://www.twitter.com/intent/tweet?url=YOURURL&text=YOURTEXT";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Basically it should open the twitter app, if twitter is unavailable it will go to the browser instead

Kristofer
  • 809
  • 9
  • 24
  • Hi, thank you. I have tried this already. I think the issue lies in 'setClassName' more specifically when setting the class name, "com.twitter.android.PostActivity" is outdated I think. Do you know of a way to find the current one the Twitter app is using? – lmathurin May 03 '18 at 01:37
  • Aye, that way does work, however, later down the line I want to add images as well. From what I've read you can't include images this way. I appreciate your help – lmathurin May 03 '18 at 01:52