Facebook and Twitter integration into App

+1 Monty Mason · November 14, 2015
Hey everyone,

Was going through Bucky's tutorial for Master Detail Flow. I decided to get a bunch of pages together including social media pages and try to use them in the app. When I try to use Facebook and twitter here is what happens.

Facebook: Opens the browser outside of the app to display the facebook page.
Twitter: Does nothing, the web view detail page is absolutely blank even though I do have the right URL.

My question is, what steps would I need to take to integrate these into the app itself rather than relying on external sources (ie. Opening a new window to display content)?

Also, if you have any instructional or informational tutorials you can share, it will be appreciated!

Thanks,

~ Monty

Post a Reply

Replies

Oldest  Newest  Rating
0 Monty Mason · November 28, 2015
@Hissam Yousaf, no problem and your welcome! =).
0 Monty Mason · November 23, 2015
@Hissam Yousaf 

I've not worked with the Facebook SDK right now. If you want to implement Facebook login for your app, then there are many tutorials covering this on YouTube. Just type, "Facebook login integration into android app" or something else along those lines.
0 Monty Mason · November 23, 2015
So as I said before (things happened in life so wasn't able to post the solution up on time), here is how I did the twitter and facebook integration.

Twitter:

- Go log into my Twitter and create a widget for the stream of tweets I wanted.
- You will get a HTML code for the widget that you can use in your code.
- Here is the code for the integration:
-- In the java code put the following:

private static final String baseURl = "https://twitter.com";

private static final String widgetInfo = "HTML_Code";

---- In the onCreate function:

WebView webView = (WebView) findViewById(R.id.webViewID);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadDataWithBaseURL(baseURl, widgetInfo, "text/html", "UTF-8", null);

Facebook:

Since I only wanted to display a company page, I didn't need to do any form of actual integration here. Keep in mind this is all for a personal project.

I implemented the following code:

private String pageId = "Facebook_pageID";

-- The following code belongs in the method you initiate Facebook with. If it's a button, it will be in a button listener (or onClick method). For me, it was in a listview:

try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + pageId));
startActivity(i);
} catch (Exception e) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + pageId));
startActivity(i);
}

The code above will make use of the facebook app if it is installed, it not then it uses the browser on the phone. The nice thing about this is that if the user were to tap on the default back symbol, it closes the browser and takes them back to the app. So it's not as immersion breaking. Same with Twitter if they wanted to login and interact with the tweet stream.
0 Monty Mason · November 19, 2015
Never mind, was able to get it to work through rigorous research and code implementation. Will post up the solution tomorrow.
  • 1

Java / Android Development

106,922 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator