diff --git a/_posts/2013-10-30-integrate-a-twitter-timeline-in-your-android-application.markdown b/_posts/2013-10-30-integrate-a-twitter-timeline-in-your-android-application.markdown index 41e8f48..d471f38 100644 --- a/_posts/2013-10-30-integrate-a-twitter-timeline-in-your-android-application.markdown +++ b/_posts/2013-10-30-integrate-a-twitter-timeline-in-your-android-application.markdown @@ -47,41 +47,50 @@ Then, I simply created a new Activity in my Application, that contains a webview {% highlight java %} package fr.lengrand.brestram; -import fr.lengrand.brestram.activities.BaseActivity; import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuItem; import android.webkit.WebView; -public class TimeLineActivity extends BaseActivity { +public class MainActivity extends ActionBarActivity { + public static final String TAG = "TimeLineActivity"; - + private static final String baseURl = "https://twitter.com"; - + private static final String widgetInfo = "Tweets about \"#BresTram\" " + ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_timeline); - + setContentView(R.layout.activity_main); + load_background_color(); - + WebView webView = (WebView) findViewById(R.id.timeline_webview); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setJavaScriptEnabled(true); - webView.loadDataWithBaseURL(baseURl, widgetInfo, "text/html", "UTF-8", null); } - - /** - * Needed because android:background does not work - * for WebViews - */ + + private void load_background_color() { WebView webView = (WebView) findViewById(R.id.timeline_webview); //webView.setBackgroundColor(getResources().getColor(R.color.twitter_dark)); webView.setBackgroundColor(0); // transparent } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + return true; + } } {% endhighlight %} @@ -112,6 +121,12 @@ 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. + +{% highlight xml %} + +{% endhighlight %} + The result is far from perfect, but it's not that bad for roughly 30 minutes of work :). twitter timeline embedded into an android application @@ -123,3 +138,5 @@ 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. + +EDIT : Edited after a request on 28th Feb. 2015. \ No newline at end of file