Reputation: 5895
I want to create one application which share image on twitter.
But when i click on button it show message "no application perform this action".
is there any wrong in following code?
private void share()
{
// TODO Auto-generated method stub
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setType("application/twitter");
tweetIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test; please ignore");
startActivity(Intent.createChooser(tweetIntent, "Choose one"));
}
Upvotes: 1
Views: 4242
Reputation: 1905
You can also use the TweetComposer. You can check this: working example with Tweet Composer Kit
From the Twitter's documentation:
The TweetComposer Kit provides two ways to compose Tweets:
- Launch the Twitter Application’s Tweet Composer - a feature-rich composer which supports attaching images and videos.
- Launch the Twitter Kit App Card Composer - a lightweight composer which lets users compose Tweets with App Cards from within your application.
If the Twitter app is not installed, the intent will launch twitter.com in a browser, but the specified image will be ignored.
If that fits to your needs it can be alternative solution. Good luck!
Upvotes: 0
Reputation: 1
After reseach, I found that you must log into twitter and create an application, then twitter will generate four parameters: consumer_key, consumer_key_secret,access_token,access_token_secret. With the secret,you can do this:
Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(config.getMediaProvider())
.setOAuthConsumerKey("...")
.setOAuthConsumerSecret(""...)
.setOAuthAccessToken("...")
.setOAuthAccessTokenSecret("...")
.build();
ImageUpload uploader = new ImageUploadFactory(conf).getInstance();
Then you can use uploader to upload your message.
Upvotes: 0
Reputation: 14750
The Twitter application needs to be installed and probably the user needs to be actively logged in (most people are) for this to work. I don't think the tweetIntent.setType("application/twitter");
works, I've never seen that. You can limit the share against Twitter by filtering by it's application package name, tweetIntent.setPackage("com.twitter.android");
. You'll want to verify that this is available to you by using the PackageManager. Here's the possible code below, I didn't test this.
Intent tweetIntent = new Intent(Intent.ACTION_SEND);
tweetIntent.setPackage("com.twitter.android");
tweetIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test; please ignore");
PackageManager pm = context.getPackageManager();
if(pm.queryIntentActivities (tweetIntent, 0).size() > 0) { // If there's at least 1 intent that matches then the intent is valid.
startActivity(Intent.createChooser(tweetIntent, "Choose one"));
} else {
// Not supported.
}
Android's share intent is meant for sending data for sharing to other applications. It's possible that you can limit the share to a specific application like you are doing. But, you're going against the grain of how Android works and you open yourself up to incompatibility issues by doing it. You might be better off using the Twitter API directly.
The rationale is that if the user doesn't have Twitter installed then chances are they don't really care about it. But they might want to share the content on another service like Facebook.
Upvotes: 1