SlideShare a Scribd company logo
Workshop:

Building Social Media Enabled
         Android Apps
      Mobile 2.0 Open Ideas
          Alberto Alonso Ruibal
       alberto.ruibal@mobialia.com
       T: @mobialia @albertoruibal
Who am I
Telecommunication Engineer
                System Manager
                J2EE Developer
Android Developer @ Mobialia
Chess apps: Mobialia Chess, Internet Chess Club
               Gas Stations Spain
                       ...
My blog: http://www.alonsoruibal.com
My company: http://www.mobialia.com
Other Android learning resources
I developed the WikiPlaces app as an example for
LabAndroid Málaga. This app contain samples of how to
do many common things on Android:
●   Dashboard
●   Creating preferences screens and retrieving preferences
●   Google Maps API, including overlays, Location API
●   Using external JSON sevices
●   Lists and adapters
●   Launching external apps with Intents
●   AdMob integration
           http://www.mobialia.com/labandroid
Why integrate social media?

● Get data from social media
● App visibility on social networks


● Sharing app data (like high scores)


● Easy login for your users on your app


● Get additional user data
Social media integration demo app




All the examples in this slides are
in a sample open-source application:

      http://www.mobialia.com/mobile20/
The share button
    ●   Very easy to implement
    ●   We can launch an “ACTION_SEND” intent to be
        received by the social media applications

    public void onShareChoose(View v) {
   String shareText = ((EditText) findViewById(R.id.EditText)
).getText().toString();
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
   startActivity(Intent.createChooser(intent,
getResources().getText(R.string.share_choose)));
}
Intents
Are an Android system that we can use
  to launch activities of the same or
        different applications

An activity launches an intent
  The intent can include “extra” data
        Other activity receives the intent
This shows the activity chooser
Choosing the component
We can launch an specific activity
(the official twitter app in this sample):

PackageManager packageManager = context.getPackageManager();

List<ResolveInfo> activityList = packageManager.queryIntentActivities(intent, 0);

for (ResolveInfo act : activityList) {

 if (act.activityInfo.name.indexOf("com.twitter.") == 0) { // Check it if starts by...

  ComponentName name = new ComponentName(act.activityInfo.applicationInfo.packageName,
act.activityInfo.name);

  intent.setComponent(name);

  startActivity(intent);

...
Twitter Integration

●   In this sample we will show our timeline
●   Twitter uses OAUTH authentication
●   Twitter API response is JSON
●   Multiple options, I prefer libsignpost
    http://code.google.com/p/oauth-signpost/
Adding signpost
Library provided in three flavours:
●   java.net.HttpUrlConnection
●   Apache Commons HTTP (we will use this)
●   Jetty HTTP Client
To use it, download:
●   signpost-core-1.2.1.1.jar
●   signpost-commonshttp4-1.2.1.1.jar
And add them to your build path on Eclipse
Getting a Twitter API key (I)
Register your app at https://dev.twitter.com/apps
Getting a Twitter API key (II)
Once registered, you can get your app's consumer
key and secret and insert them in the code:




OAuthConsumer oauthConsumer = new CommonsHttpOAuthConsumer(
  // the consumer key of this app (replace this with yours)
  "RFbRzd0BzYGZjrDd02ec5g" ,
  // the consumer secret of this app (replace this with yours)
  "wo9lKhzwpEfdXS2Z3dO2W092W9pMoJGrc5kUsBdA");
Authenticating user
Now we redirect our users to the authentication URL,
specifying a callback URL:
public static String CALLBACK_URL = "socialmediademo://twitter";
//...
 String authUrl = oauthProvider.retrieveRequestToken(oauthConsumer,
CALLBACK_URL);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
// save token
accessToken     = oauthConsumer.getToken();
tokenSecret = oauthConsumer.getTokenSecret();
 intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND |
Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Twitter Authentication



Twitter page is opened on
the system web browser


This sample is read-only
(no post or follow)
Intercepting Callback URL
We intercept the callback “socialmediademo://twitter” URL
modifying the AndroidManifest.xml:
<activity
android:name =".TwitterProviderActivity"
android:label ="@string/app_name">
<intent-filter>
 <action android:name="android.intent.action.VIEW"></action>
 <category android:name="android.intent.category.DEFAULT"></category>
 <category android:name="android.intent.category.BROWSABLE"></category>
 <data android:scheme="socialmediademo" android:host="twitter"></data>
</intent-filter>
</activity>
Verifying user login
Then, on the receiving activity
(TwitterProviderActivity):

Uri uri = this.getIntent().getData();
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
oauthConsumer.setTokenWithSecret(accessToken, tokenSecret);
oauthProvider.retrieveAccessToken(oauthConsumer, verifier);
// save new token
accessToken   = oauthConsumer.getToken();
tokenSecret = oauthConsumer.getTokenSecret();
Getting updates from timeline
Now we can query Twitter REST API methods:

 String url =
"http://api.twitter.com/1/statuses/home_timeline.json?count=100";
HttpGet request = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
// sign the request
oauthConsumer.setTokenWithSecret(accessToken, tokenSecret);
oauthConsumer.sign(request);
HttpResponse response = httpClient.execute(request);
Parsing the JSON responses
Android API integrates a JSON parser!

JSONArray array = new JSONArray(response);
for (int i = 0; i < array.length(); i++) {
    JSONObject user = object.getJSONObject("user");
    Update update = new Update();
  update.setMessage(Html.fromHtml(object.getString("text")
).toString());
    update.setUserId(user.getString("screen_name"));
    update.setUserName(user.getString("name"));
// ...
Finally we show the updates

           On the source code you
           can also find:
           ●   List adapter for updates
           ●   Image Cache
LinkedIn Integration
●   Very similar to Twitter, we can also use
    libsignpost
●   XML/JSON API
●   A small difference: we need to specify to
    signpost that LinkedIn uses OAUTH version
    1.0a:
     oauthProvider.setOAuth10a(true);
Getting a LinkedIn API key
https://www.linkedin.com/secure/developer
LinkedIn Authentication


         Works like Twitter, opening it
         on the system's browser.


         We also have a callback URL
Calling the LinkedIn API
By default in XML, we must send the parameter
“&format=json”

String response =
httpRequest("http://api.linkedin.com/v1/people/~/network/updates?
count=100&format=json");
if (response != null) {
JSONObject object = new JSONObject(response);
//...
LinkedIn result


     Shows updates from your
     LinkedIn contacts
Using social media for logging-in
No need to create a user account
I recommend Facebook:
   ● More users


   ● More user data


We can get additional user information!
   ● Gender


   ● Birthday


   ● ...
Facebook Integration

●   Uses OAUTH 2.0, signpost does not support it
●   Download Facebook SDK from Github:
    https://github.com/facebook/facebook-android-sdk/
●   We need to add the Facebook SDK as a
    separate project and add a project dependency
●   Use the new Graph API methods!
Getting a Facebook API key (I)
https://www.facebook.com/developers/
Getting a Facebook API key (II)
Here we have the Application ID
To obtain the key hash: keytool -exportcert -alias androiddebugkey
-keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl
base64
Preparing the Facebook Object
And launching the facebook authentication...

final   int ACTIVITY_CODE = 777;
final String appId = "219172308103195";
final String[] PERMISSIONS = new String[] { "user_birthday" };


Facebook fb = new Facebook(appId);
fb.authorize(this, PERMISSIONS, ACTIVITY_CODE, this);
// (Callback not detailed)
Login with Facebook

        Opens a Facebook
        Activity requesting
        authentication data
Getting user data from Facebook
When we are authenticated, we can do requests,
“/me” gets user information

String res = fb.request("/me");
JSONObject object = new JSONObject(res);
Log.d(TAG, object.getString("id"));
Log.d(TAG, object.getString("name"));
Log.d(TAG, object.getString("gender"));
Log.d(TAG, object.getString("birthday"));
Improving ads with user data
●   With AdMob we can specify user gender and
    birthday:
AdRequest adRequest = new AdRequest();
adRequest.setGender(Gender.FEMALE);
adRequest.setBirthday("19790129");
AdView adView = (AdView) this.findViewById(R.id.adView)
adView.loadAd(adRequest);
Facebook result
    The demo app shows the
    user data
    The Ad shown is requested
    with the user data
    We can use the user data on
    may parts of our application
More ideas
● You can also use a WebView to
  integrate social media features
● “Follow” button integrating twitter API


● “Like” button: needs to create a

  facebook object associated
● “Foursquare” API integration
Questions...


Thanks for your attention!


       Alberto Alonso Ruibal
    alberto.ruibal@mobialia.com
      http://www.mobialia.com
    T: @mobialia @albertoruibal

More Related Content

What's hot

Android 3
Android 3Android 3
Android 3
Robert Cooper
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
ma-polimi
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codes
Aravindharamanan S
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
Jussi Pohjolainen
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
vishal choudhary
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
Marcos Paulo Souza Damasceno
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification Tutorial
Ketan Raval
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
vishal choudhary
 
Android best practices
Android best practicesAndroid best practices
Android best practices
Jose Manuel Ortega Candel
 
Open social 2.0 sandbox ee and breaking out of the gadget box
Open social 2.0 sandbox  ee and breaking out of the gadget boxOpen social 2.0 sandbox  ee and breaking out of the gadget box
Open social 2.0 sandbox ee and breaking out of the gadget box
Ryan Baxter
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
Raman Pandey
 
Application Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyApplication Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The Ugly
Richard Lord
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application Tutorial
Ishara Amarasekera
 
Android session 3
Android session 3Android session 3
Android session 3
Ahesanali Suthar
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
Robert Cooper
 
Android session 2
Android session 2Android session 2
Android session 2
Ahesanali Suthar
 
Advanced Android gReporter
Advanced Android gReporterAdvanced Android gReporter
Advanced Android gReporter
natdefreitas
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 

What's hot (20)

Android 3
Android 3Android 3
Android 3
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Android
 
Android ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codesAndroid ui layouts ,cntls,webservices examples codes
Android ui layouts ,cntls,webservices examples codes
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification Tutorial
 
Develop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptxDevelop a native application that uses GPS location.pptx
Develop a native application that uses GPS location.pptx
 
Android best practices
Android best practicesAndroid best practices
Android best practices
 
Open social 2.0 sandbox ee and breaking out of the gadget box
Open social 2.0 sandbox  ee and breaking out of the gadget boxOpen social 2.0 sandbox  ee and breaking out of the gadget box
Open social 2.0 sandbox ee and breaking out of the gadget box
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Application Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The UglyApplication Frameworks - The Good, The Bad & The Ugly
Application Frameworks - The Good, The Bad & The Ugly
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application Tutorial
 
Android session 3
Android session 3Android session 3
Android session 3
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in Android
 
Android session 2
Android session 2Android session 2
Android session 2
 
Advanced Android gReporter
Advanced Android gReporterAdvanced Android gReporter
Advanced Android gReporter
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 

Similar to Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android

OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
Pamela Fox
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
PushApps - Content Recommendation in Push Notifications
 
Open Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKsOpen Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKs
Dustin Whittle
 
Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
SudhanshiBakre1
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updated
GhanaGTUG
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
NgLQun
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
firenze-gtug
 
Mobile, web and cloud - the triple crown of modern applications
Mobile, web and cloud -  the triple crown of modern applicationsMobile, web and cloud -  the triple crown of modern applications
Mobile, web and cloud - the triple crown of modern applications
Ido Green
 
Google+ sign in for mobile & web apps
Google+ sign in for mobile & web appsGoogle+ sign in for mobile & web apps
Google+ sign in for mobile & web apps
Lakhdar Meftah
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
Kanda Runapongsa Saikaew
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
Junda Ong
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
maamir farooq
 
android level 3
android level 3android level 3
android level 3
DevMix
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
mharkus
 
How to implement sso using o auth in golang application
How to implement sso using o auth in golang applicationHow to implement sso using o auth in golang application
How to implement sso using o auth in golang application
Katy Slemon
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratch
Katy Slemon
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part One
Aaron Saunders
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
easychen
 
Android architecture
Android architecture Android architecture
Android architecture
Trong-An Bui
 

Similar to Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android (20)

OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
 
Open Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKsOpen Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKs
 
Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updated
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloud
 
Mobile, web and cloud - the triple crown of modern applications
Mobile, web and cloud -  the triple crown of modern applicationsMobile, web and cloud -  the triple crown of modern applications
Mobile, web and cloud - the triple crown of modern applications
 
Google+ sign in for mobile & web apps
Google+ sign in for mobile & web appsGoogle+ sign in for mobile & web apps
Google+ sign in for mobile & web apps
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Android Workshop
Android WorkshopAndroid Workshop
Android Workshop
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
android level 3
android level 3android level 3
android level 3
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
How to implement sso using o auth in golang application
How to implement sso using o auth in golang applicationHow to implement sso using o auth in golang application
How to implement sso using o auth in golang application
 
How to build twitter bot using golang from scratch
How to build twitter bot using golang from scratchHow to build twitter bot using golang from scratch
How to build twitter bot using golang from scratch
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part One
 
Android应用开发简介
Android应用开发简介Android应用开发简介
Android应用开发简介
 
Android architecture
Android architecture Android architecture
Android architecture
 

More from Alberto Ruibal

Xornada "Novos Perfís profesionais na Era Dixital"
Xornada "Novos Perfís profesionais na Era Dixital"Xornada "Novos Perfís profesionais na Era Dixital"
Xornada "Novos Perfís profesionais na Era Dixital"
Alberto Ruibal
 
Mobialia Gas Stations Spain
Mobialia Gas Stations SpainMobialia Gas Stations Spain
Mobialia Gas Stations Spain
Alberto Ruibal
 
Modelos de Negocio para Aplicaciones Móviles
Modelos de Negocio para Aplicaciones MóvilesModelos de Negocio para Aplicaciones Móviles
Modelos de Negocio para Aplicaciones Móviles
Alberto Ruibal
 
Appcircus Academy: Integración de Social Media en Android
Appcircus Academy: Integración de Social Media en AndroidAppcircus Academy: Integración de Social Media en Android
Appcircus Academy: Integración de Social Media en Android
Alberto Ruibal
 
MobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a AndroidMobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a Android
Alberto Ruibal
 
Mobialia Chess DevFest
Mobialia Chess DevFestMobialia Chess DevFest
Mobialia Chess DevFest
Alberto Ruibal
 
LabAndroid: Taller "Mi Primera Aplicación Android"
LabAndroid: Taller "Mi Primera Aplicación Android"LabAndroid: Taller "Mi Primera Aplicación Android"
LabAndroid: Taller "Mi Primera Aplicación Android"
Alberto Ruibal
 

More from Alberto Ruibal (7)

Xornada "Novos Perfís profesionais na Era Dixital"
Xornada "Novos Perfís profesionais na Era Dixital"Xornada "Novos Perfís profesionais na Era Dixital"
Xornada "Novos Perfís profesionais na Era Dixital"
 
Mobialia Gas Stations Spain
Mobialia Gas Stations SpainMobialia Gas Stations Spain
Mobialia Gas Stations Spain
 
Modelos de Negocio para Aplicaciones Móviles
Modelos de Negocio para Aplicaciones MóvilesModelos de Negocio para Aplicaciones Móviles
Modelos de Negocio para Aplicaciones Móviles
 
Appcircus Academy: Integración de Social Media en Android
Appcircus Academy: Integración de Social Media en AndroidAppcircus Academy: Integración de Social Media en Android
Appcircus Academy: Integración de Social Media en Android
 
MobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a AndroidMobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a Android
 
Mobialia Chess DevFest
Mobialia Chess DevFestMobialia Chess DevFest
Mobialia Chess DevFest
 
LabAndroid: Taller "Mi Primera Aplicación Android"
LabAndroid: Taller "Mi Primera Aplicación Android"LabAndroid: Taller "Mi Primera Aplicación Android"
LabAndroid: Taller "Mi Primera Aplicación Android"
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 

Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android

  • 1. Workshop: Building Social Media Enabled Android Apps Mobile 2.0 Open Ideas Alberto Alonso Ruibal alberto.ruibal@mobialia.com T: @mobialia @albertoruibal
  • 2. Who am I Telecommunication Engineer System Manager J2EE Developer Android Developer @ Mobialia Chess apps: Mobialia Chess, Internet Chess Club Gas Stations Spain ... My blog: http://www.alonsoruibal.com My company: http://www.mobialia.com
  • 3. Other Android learning resources I developed the WikiPlaces app as an example for LabAndroid Málaga. This app contain samples of how to do many common things on Android: ● Dashboard ● Creating preferences screens and retrieving preferences ● Google Maps API, including overlays, Location API ● Using external JSON sevices ● Lists and adapters ● Launching external apps with Intents ● AdMob integration http://www.mobialia.com/labandroid
  • 4. Why integrate social media? ● Get data from social media ● App visibility on social networks ● Sharing app data (like high scores) ● Easy login for your users on your app ● Get additional user data
  • 5. Social media integration demo app All the examples in this slides are in a sample open-source application: http://www.mobialia.com/mobile20/
  • 6. The share button ● Very easy to implement ● We can launch an “ACTION_SEND” intent to be received by the social media applications public void onShareChoose(View v) { String shareText = ((EditText) findViewById(R.id.EditText) ).getText().toString(); Intent intent = new Intent(android.content.Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(android.content.Intent.EXTRA_TEXT, shareText); startActivity(Intent.createChooser(intent, getResources().getText(R.string.share_choose))); }
  • 7. Intents Are an Android system that we can use to launch activities of the same or different applications An activity launches an intent The intent can include “extra” data Other activity receives the intent
  • 8. This shows the activity chooser
  • 9. Choosing the component We can launch an specific activity (the official twitter app in this sample): PackageManager packageManager = context.getPackageManager(); List<ResolveInfo> activityList = packageManager.queryIntentActivities(intent, 0); for (ResolveInfo act : activityList) { if (act.activityInfo.name.indexOf("com.twitter.") == 0) { // Check it if starts by... ComponentName name = new ComponentName(act.activityInfo.applicationInfo.packageName, act.activityInfo.name); intent.setComponent(name); startActivity(intent); ...
  • 10. Twitter Integration ● In this sample we will show our timeline ● Twitter uses OAUTH authentication ● Twitter API response is JSON ● Multiple options, I prefer libsignpost http://code.google.com/p/oauth-signpost/
  • 11. Adding signpost Library provided in three flavours: ● java.net.HttpUrlConnection ● Apache Commons HTTP (we will use this) ● Jetty HTTP Client To use it, download: ● signpost-core-1.2.1.1.jar ● signpost-commonshttp4-1.2.1.1.jar And add them to your build path on Eclipse
  • 12. Getting a Twitter API key (I) Register your app at https://dev.twitter.com/apps
  • 13. Getting a Twitter API key (II) Once registered, you can get your app's consumer key and secret and insert them in the code: OAuthConsumer oauthConsumer = new CommonsHttpOAuthConsumer( // the consumer key of this app (replace this with yours) "RFbRzd0BzYGZjrDd02ec5g" , // the consumer secret of this app (replace this with yours) "wo9lKhzwpEfdXS2Z3dO2W092W9pMoJGrc5kUsBdA");
  • 14. Authenticating user Now we redirect our users to the authentication URL, specifying a callback URL: public static String CALLBACK_URL = "socialmediademo://twitter"; //... String authUrl = oauthProvider.retrieveRequestToken(oauthConsumer, CALLBACK_URL); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)); // save token accessToken = oauthConsumer.getToken(); tokenSecret = oauthConsumer.getTokenSecret(); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);
  • 15. Twitter Authentication Twitter page is opened on the system web browser This sample is read-only (no post or follow)
  • 16. Intercepting Callback URL We intercept the callback “socialmediademo://twitter” URL modifying the AndroidManifest.xml: <activity android:name =".TwitterProviderActivity" android:label ="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW"></action> <category android:name="android.intent.category.DEFAULT"></category> <category android:name="android.intent.category.BROWSABLE"></category> <data android:scheme="socialmediademo" android:host="twitter"></data> </intent-filter> </activity>
  • 17. Verifying user login Then, on the receiving activity (TwitterProviderActivity): Uri uri = this.getIntent().getData(); String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER); oauthConsumer.setTokenWithSecret(accessToken, tokenSecret); oauthProvider.retrieveAccessToken(oauthConsumer, verifier); // save new token accessToken = oauthConsumer.getToken(); tokenSecret = oauthConsumer.getTokenSecret();
  • 18. Getting updates from timeline Now we can query Twitter REST API methods: String url = "http://api.twitter.com/1/statuses/home_timeline.json?count=100"; HttpGet request = new HttpGet(url); HttpClient httpClient = new DefaultHttpClient(); // sign the request oauthConsumer.setTokenWithSecret(accessToken, tokenSecret); oauthConsumer.sign(request); HttpResponse response = httpClient.execute(request);
  • 19. Parsing the JSON responses Android API integrates a JSON parser! JSONArray array = new JSONArray(response); for (int i = 0; i < array.length(); i++) { JSONObject user = object.getJSONObject("user"); Update update = new Update(); update.setMessage(Html.fromHtml(object.getString("text") ).toString()); update.setUserId(user.getString("screen_name")); update.setUserName(user.getString("name")); // ...
  • 20. Finally we show the updates On the source code you can also find: ● List adapter for updates ● Image Cache
  • 21. LinkedIn Integration ● Very similar to Twitter, we can also use libsignpost ● XML/JSON API ● A small difference: we need to specify to signpost that LinkedIn uses OAUTH version 1.0a: oauthProvider.setOAuth10a(true);
  • 22. Getting a LinkedIn API key https://www.linkedin.com/secure/developer
  • 23. LinkedIn Authentication Works like Twitter, opening it on the system's browser. We also have a callback URL
  • 24. Calling the LinkedIn API By default in XML, we must send the parameter “&format=json” String response = httpRequest("http://api.linkedin.com/v1/people/~/network/updates? count=100&format=json"); if (response != null) { JSONObject object = new JSONObject(response); //...
  • 25. LinkedIn result Shows updates from your LinkedIn contacts
  • 26. Using social media for logging-in No need to create a user account I recommend Facebook: ● More users ● More user data We can get additional user information! ● Gender ● Birthday ● ...
  • 27. Facebook Integration ● Uses OAUTH 2.0, signpost does not support it ● Download Facebook SDK from Github: https://github.com/facebook/facebook-android-sdk/ ● We need to add the Facebook SDK as a separate project and add a project dependency ● Use the new Graph API methods!
  • 28. Getting a Facebook API key (I) https://www.facebook.com/developers/
  • 29. Getting a Facebook API key (II) Here we have the Application ID To obtain the key hash: keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
  • 30. Preparing the Facebook Object And launching the facebook authentication... final int ACTIVITY_CODE = 777; final String appId = "219172308103195"; final String[] PERMISSIONS = new String[] { "user_birthday" }; Facebook fb = new Facebook(appId); fb.authorize(this, PERMISSIONS, ACTIVITY_CODE, this); // (Callback not detailed)
  • 31. Login with Facebook Opens a Facebook Activity requesting authentication data
  • 32. Getting user data from Facebook When we are authenticated, we can do requests, “/me” gets user information String res = fb.request("/me"); JSONObject object = new JSONObject(res); Log.d(TAG, object.getString("id")); Log.d(TAG, object.getString("name")); Log.d(TAG, object.getString("gender")); Log.d(TAG, object.getString("birthday"));
  • 33. Improving ads with user data ● With AdMob we can specify user gender and birthday: AdRequest adRequest = new AdRequest(); adRequest.setGender(Gender.FEMALE); adRequest.setBirthday("19790129"); AdView adView = (AdView) this.findViewById(R.id.adView) adView.loadAd(adRequest);
  • 34. Facebook result The demo app shows the user data The Ad shown is requested with the user data We can use the user data on may parts of our application
  • 35. More ideas ● You can also use a WebView to integrate social media features ● “Follow” button integrating twitter API ● “Like” button: needs to create a facebook object associated ● “Foursquare” API integration
  • 36. Questions... Thanks for your attention! Alberto Alonso Ruibal alberto.ruibal@mobialia.com http://www.mobialia.com T: @mobialia @albertoruibal