I’m working on an Android application that allows users to share an article via Facebook and/or Twitter. Facebook share works well using ShareDialog, which opens up Facebook share dialog in my application.
The problem I’m having is with posting to Twitter. If the user has a Twitter app installed, share works perfectly. When there is no Twitter app installed on the device, then the Twitter share page is opened in the default browser and user never gets returned to my application after tweeting, which is kind of a bad user experience.
My code for tweet posting is:
Intent intent = new TweetComposer.Builder(context).text("Tweet text.").createIntent();
startActivityForResult(intent, SHARE_ACTION_TWITTER);
I have also tried this:
TweetComposer.Builder builder = new TweetComposer.Builder(this).text("Tweet text.");
builder.show();
Is there a way to get a dialog in my application (similar to Facebook share behavior) when the user does not have the Twitter app installed?
Additionally, for statistics, I would like to know if the user has successfully posted a tweet. How can this be achieved with Fabric Twitter API if user does not have Twitter app installed? Should I use a different API?
3
Answers
The solution was to create a custom webview for tweeting. It doesn't even require the Fabric Twitter API.
Most important part is to create a webview activity:
And a layout like this:
In the AndroidManifest.xml we must add the activity for our webview inside the
<application>
tag:Last step is to call our vebview when user taps Share on Twitter button:
That should be it. I hope this will help someone.
use below code to post status to twitter.it use’s twitter’s rest api calls:
i am sharing successfully from my app. it doesn’t require twitter app to be installed.
I guess the correct answer is using Update Status API call.
I’m using the latest Twitter SDK version:
com.twitter.sdk.android:twitter:3.1.1
NOTE
The user must be authenticated before calling this API call.
For further details, check this post on Twitter Dev Forum.
Best regards