Integrate a twitter timeline in your android application.
Hey all,
This week-end, I worked on integrating a social feature in BresTram.
I needed a way to let the users know when the bibus servers have a problem, and also let users send messages to each others if needed.
Finally, I didn’t want to spend too much time developing it. I have more pressing features to implement, and the social integration is more of a “test”.
I decided to go with Twitter. The message will generally be short (work on the rails, problems with the tram, …), and everybody should be able to see them.
I started looking at the Streaming API, but then realized there was a much simpler way to do it : Simply integrate a web timeline into my app.
I started by creating a dedicated filter on the twitter account of BresTram.
This gives me two lines of code to integrate into the website of my choice :
Then, I simply created a new Activity in my Application, that contains a webview.
The background color method is needed to avoid the ugly white background behind the timeline. I use a transparent background in this case.
It is not possible to set the background directly in the xml layout for webviews; you will have to do it in the activity directly.
And here is the layout file :
I used fill_parent because I wanted to give as much space as possible to the Webview.
The last thing you want to do is make sure you are allowing your app to make web calls. For that, add this line in your Android Manifest.
The result is far from perfect, but it’s not that bad for roughly 30 minutes of work :).
On top of that, It directly allows my users to post tweets from the application (using the timeline), and will let everybody know about the BresTram twitter account.
Hopefully, this will help me get some useful feedback.
Now, back to more complex features :).
Oh, and if you leave near Brest, check out BresTram!
P.S: This is not exactly how the actual source code look like. I changed several things to highlight the essentials in this post.