This is what I do to share stuff with twitter:
tweetButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
initShareIntentTwi("twi");
}
});
private void initShareIntentTwi(String type) {
boolean found = false;
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(
share, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName.toLowerCase().contains(type)
|| info.activityInfo.name.toLowerCase().contains(type)) {
share.putExtra(Intent.EXTRA_TEXT, title + " "
+ shorturl);
share.setPackage(info.activityInfo.packageName);
found = true;
break;
}
}
if (!found) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Twitter");
LinearLayout wrapper = new LinearLayout(this);
WebView webView = new WebView(this);
EditText keyboardHack = new EditText(this);
keyboardHack.setVisibility(View.GONE);
webView.loadUrl("https://twitter.com/intent/tweet?status="
+ titulo + "%20" + shorturl);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
view.loadUrl(url);
return true;
}
});
wrapper.setOrientation(LinearLayout.VERTICAL);
wrapper.addView(webView,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(keyboardHack,
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
builder.setView(wrapper);
builder.setNegativeButton("Close",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
builder.create().show();
return;
}
startActivity(Intent.createChooser(share, "Select"));
}
}
If the user has the Twitter apps, this will open it and if doesn't it will open a alert dialog with a webview containing this :" https://twitter.com/intent/tweet?status=" plus the text that you want to share. You can ignore this part if you want and just show a alert dialog asking for the app or something like this.