简体   繁体   中英

How to post to social media automatically? Android

In my application I want to allow posting to social media (lets use Twitter as example) using voice command. The conflict I am running into is that starting an intent for ACTION_SEND still requires the user to press the "tweet" button to ultimately post the message. Is there any way to post to twitter without that final step?

Lets do a simple example for making a post to Twitter via the app.

                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("text/plain"); //application/twitter
                    intent.setPackage("com.twitter.android");
                    intent.putExtra(Intent.EXTRA_TEXT, "Test; please ignore");
                    SocialMediaActivity.this.startActivity(intent);

The above code will open the twitter application, the text "Test; please ignore" will be the message in the tweet. But the end user has to press the tweet button in the top right corner to finish the action. How to just post to twitter and then return back to the app?

Use Twitter API. You can find info how to use it on the official site: Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM