SlideShare a Scribd company logo
1 of 36
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

Events and Listeners in Android
Events and Listeners in AndroidEvents and Listeners in Android
Events and Listeners in Androidma-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 codesAravindharamanan S
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification TutorialKetan 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.pptxvishal choudhary
 
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 boxRyan Baxter
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentRaman 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 UglyRichard Lord
 
iOS Contact List Application Tutorial
iOS Contact List Application TutorialiOS Contact List Application Tutorial
iOS Contact List Application TutorialIshara Amarasekera
 
What's New in Android
What's New in AndroidWhat's New in Android
What's New in AndroidRobert Cooper
 
Advanced Android gReporter
Advanced Android gReporterAdvanced Android gReporter
Advanced Android gReporternatdefreitas
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivityAhsanul 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 IntroPamela Fox
 
Open Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKsOpen Hack NYC Yahoo Social SDKs
Open Hack NYC Yahoo Social SDKsDustin 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.pdfSudhanshiBakre1
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updatedGhanaGTUG
 
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.pptxNgLQun
 
Android chat in the cloud
Android chat in the cloudAndroid chat in the cloud
Android chat in the cloudfirenze-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 applicationsIdo 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 appsLakhdar Meftah
 
Android Workshop
Android WorkshopAndroid Workshop
Android WorkshopJunda Ong
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
android level 3
android level 3android level 3
android level 3DevMix
 
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 applicationKaty 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 scratchKaty Slemon
 
StackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneStackMob & Appcelerator Module Part One
StackMob & Appcelerator Module Part OneAaron 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 SpainAlberto 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óvilesAlberto 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 AndroidAlberto Ruibal
 
MobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a AndroidMobileCONGalicia Introducción a Android
MobileCONGalicia Introducción a AndroidAlberto Ruibal
 
Mobialia Chess DevFest
Mobialia Chess DevFestMobialia Chess DevFest
Mobialia Chess DevFestAlberto 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

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.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