SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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
 

Más de 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
 

Más de 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"
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.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