How can I post on Twitter with Intent Action_send?

I have been struggling to send text from my app to Twitter.

The code below works to bring up a list of apps such as Bluetooth, Gmail, Facebook and Twitter, but when I select Twitter it doesn’t prefill the text as I would have expected.

  • Eclipse Android Debugger - Where in my code did I cause the exception?
  • Is dp the same as dip?
  • Android HttpURLConnection throwing EOFException
  • Android emulator network config
  • JWPlayer Javascript API for Android Webview
  • Generating a Pro Guard configuration file with Android Studio
  • I know that there are issues around doing this with Facebook, but I must be doing something wrong for it to not be working with Twitter.

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, "Example Text");
    startActivity(Intent.createChooser(intent, "Share Text"));

  • Android OpenGL Texture Compression
  • JSON Java check element is a JSONArray or JSONObject
  • Picasso Image downloaded again for an ImageView with different dimensions?
  • Programmatically scroll to the top of a NestedScrollView
  • Android v7 Toolbar button alignment
  • How can I get the magnetic field vector, independent of the device rotation?
  • 5 Solutions collect form web for “How can I post on Twitter with Intent Action_send?”

    I’m using this snippet on my code:

    Intent tweetIntent = new Intent(Intent.ACTION_SEND);
    tweetIntent.putExtra(Intent.EXTRA_TEXT, "This is a Test.");
    PackageManager packManager = getPackageManager();
    List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(tweetIntent,  PackageManager.MATCH_DEFAULT_ONLY);
    boolean resolved = false;
    for(ResolveInfo resolveInfo: resolvedInfoList){
            resolved = true;
        Intent i = new Intent();
        i.putExtra(Intent.EXTRA_TEXT, message);
        Toast.makeText(this, "Twitter app isn't found", Toast.LENGTH_LONG).show();
    private String urlEncode(String s) {
        try {
            return URLEncoder.encode(s, "UTF-8");
        }catch (UnsupportedEncodingException e) {
  , "UTF-8 should always be supported", e);
            return "";

    Hope it helps.

    you can simply open the URL with the text and Twitter App will do it. 😉

    String url = "";
    Intent i = new Intent(Intent.ACTION_VIEW);

    and it will also open the browser to login at the tweet if twitter app is not found.

    First you have to check if the twitter app installed on the device or not then share the text on twitter:

            // Check if the Twitter app is installed on the phone.
            getActivity().getPackageManager().getPackageInfo("", 0);
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setClassName("", "");
            intent.putExtra(Intent.EXTRA_TEXT, "Your text");
        catch (Exception e)
            Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show();

    Try this, I used it and worked great

      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(""));

    For sharing text and image on Twitter, more controlled version of code is below, you can add more methods for sharing with WhatsApp, Facebook … This is for official App and does not open browser if app not exists.

    public class IntentShareHelper {
        public static void shareOnTwitter(AppCompatActivity appCompatActivity, String textBody, Uri fileUri) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.putExtra(Intent.EXTRA_TEXT,!TextUtils.isEmpty(textBody) ? textBody : "");
            if (fileUri != null) {
                intent.putExtra(Intent.EXTRA_STREAM, fileUri);
            try {
            } catch (android.content.ActivityNotFoundException ex) {
                showWarningDialog(appCompatActivity, appCompatActivity.getString(R.string.error_activity_not_found));
        public static void shareOnWhatsapp(AppCompatActivity appCompatActivity, String textBody, Uri fileUri){...}
        private static void showWarningDialog(Context context, String message) {
            new AlertDialog.Builder(context)
                    .setNegativeButton(context.getString(R.string.close), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

    For getting Uri from File, use below class:

    public class UtilityFile {
        public static @Nullable Uri getUriFromFile(Context context, @Nullable File file) {
            if (file == null)
                return null;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                try {
                    return FileProvider.getUriForFile(context, "", file);
                } catch (Exception e) {
                    return null;
            } else {
                return Uri.fromFile(file);
        // Returns the URI path to the Bitmap displayed in specified ImageView       
        public static Uri getLocalBitmapUri(Context context, ImageView imageView) {
            Drawable drawable = imageView.getDrawable();
            Bitmap bmp = null;
            if (drawable instanceof BitmapDrawable) {
                bmp = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
            } else {
                return null;
            // Store image to default external storage directory
            Uri bmpUri = null;
            try {
                // Use methods on Context to access package-specific directories on external storage.
                // This way, you don't need to request external read/write permission.
                File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
                FileOutputStream out = new FileOutputStream(file);
                bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
                bmpUri = getUriFromFile(context, file);
            } catch (IOException e) {
            return bmpUri;

    For writing FileProvider, use this link:

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.