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

PPTX
Google Plus SignIn : l'Authentification Google
PPTX
ProTips DroidCon Paris 2013
PDF
Android Sliding Menu dengan Navigation Drawer
PDF
AI: Mobile Apps That Understands Your Intention When You Typed
PDF
Cross-Platform Authentication with Google+ Sign-In
PDF
Tutorial basicapp
PDF
Google+ for Mobile Apps on iOS and Android
PDF
Android Cloud to Device Messaging Framework at GTUG Stockholm
Google Plus SignIn : l'Authentification Google
ProTips DroidCon Paris 2013
Android Sliding Menu dengan Navigation Drawer
AI: Mobile Apps That Understands Your Intention When You Typed
Cross-Platform Authentication with Google+ Sign-In
Tutorial basicapp
Google+ for Mobile Apps on iOS and Android
Android Cloud to Device Messaging Framework at GTUG Stockholm

What's hot (20)

PPTX
Android 3
ODP
Ppt 2 android_basics
PDF
Events and Listeners in Android
PDF
Android ui layouts ,cntls,webservices examples codes
PDF
Android Basic Components
PPTX
Android Intent.pptx
PDF
Android UI Fundamentals part 1
PDF
Android Components
DOCX
Local Notification Tutorial
PPTX
Develop a native application that uses GPS location.pptx
PDF
Android best practices
PPTX
Open social 2.0 sandbox ee and breaking out of the gadget box
PPTX
Android apps development
KEY
Application Frameworks - The Good, The Bad & The Ugly
PDF
iOS Contact List Application Tutorial
PDF
Android session 3
PPTX
What's New in Android
PDF
Android session 2
PDF
Advanced Android gReporter
PPTX
Android MapView and MapActivity
Android 3
Ppt 2 android_basics
Events and Listeners in Android
Android ui layouts ,cntls,webservices examples codes
Android Basic Components
Android Intent.pptx
Android UI Fundamentals part 1
Android Components
Local Notification Tutorial
Develop a native application that uses GPS location.pptx
Android best practices
Open social 2.0 sandbox ee and breaking out of the gadget box
Android apps development
Application Frameworks - The Good, The Bad & The Ugly
iOS Contact List Application Tutorial
Android session 3
What's New in Android
Android session 2
Advanced Android gReporter
Android MapView and MapActivity
Ad

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

PPT
OpenSocial Intro
DOCX
How to create android push notifications with custom view
PDF
IT3681 - MOBILE_APPLICATIONS_DEVELOPMENT_LABORATORY (1).pdf
PPTX
Open Hack NYC Yahoo Social SDKs
PDF
Android Quiz App – Test Your IQ.pdf
PPT
21 android2 updated
PPTX
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
PDF
Android chat in the cloud
PDF
Mobile, web and cloud - the triple crown of modern applications
PPTX
Google+ sign in for mobile & web apps
PDF
Introduction to Google App Engine
KEY
Android Workshop
DOCX
Leture5 exercise onactivities
DOCX
Lecture exercise on activities
PDF
android level 3
PPTX
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
PDF
How to implement sso using o auth in golang application
PDF
How to build twitter bot using golang from scratch
DOCX
Mobile Application Development Lab Mannual 2024.docx
PDF
StackMob & Appcelerator Module Part One
OpenSocial Intro
How to create android push notifications with custom view
IT3681 - MOBILE_APPLICATIONS_DEVELOPMENT_LABORATORY (1).pdf
Open Hack NYC Yahoo Social SDKs
Android Quiz App – Test Your IQ.pdf
21 android2 updated
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Android chat in the cloud
Mobile, web and cloud - the triple crown of modern applications
Google+ sign in for mobile & web apps
Introduction to Google App Engine
Android Workshop
Leture5 exercise onactivities
Lecture exercise on activities
android level 3
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
How to implement sso using o auth in golang application
How to build twitter bot using golang from scratch
Mobile Application Development Lab Mannual 2024.docx
StackMob & Appcelerator Module Part One
Ad

More from Alberto Ruibal (7)

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

Recently uploaded (20)

PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
A Presentation on Touch Screen Technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Getting Started with Data Integration: FME Form 101
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
project resource management chapter-09.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Hindi spoken digit analysis for native and non-native speakers
SOPHOS-XG Firewall Administrator PPT.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Web App vs Mobile App What Should You Build First.pdf
DP Operators-handbook-extract for the Mautical Institute
A Presentation on Touch Screen Technology
Unlocking AI with Model Context Protocol (MCP)
cloud_computing_Infrastucture_as_cloud_p
Group 1 Presentation -Planning and Decision Making .pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Chapter 5: Probability Theory and Statistics
Getting Started with Data Integration: FME Form 101
Univ-Connecticut-ChatGPT-Presentaion.pdf
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
project resource management chapter-09.pdf
1. Introduction to Computer Programming.pptx
Heart disease approach using modified random forest and particle swarm optimi...
Accuracy of neural networks in brain wave diagnosis of schizophrenia

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