How can I post on Twitter with Intent Action_send?

后端 未结 5 1729
野趣味
野趣味 2020-12-05 15:37

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

5条回答
  •  眼角桃花
    2020-12-05 16:24

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

    try
        {
            // Check if the Twitter app is installed on the phone.
            getActivity().getPackageManager().getPackageInfo("com.twitter.android", 0);
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setClassName("com.twitter.android", "com.twitter.android.composer.ComposerActivity");
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, "Your text");
            startActivity(intent);
    
        }
        catch (Exception e)
        {
            Toast.makeText(getActivity(),"Twitter is not installed on this device",Toast.LENGTH_LONG).show();
    
        }
    

提交回复
热议问题