Android SDK Setup

From Social ID Developers
(Difference between revisions)
Jump to: navigation, search
m (Android Manifest)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= Download the SDK =
+
= Configure CoffeeBean SDK in your app =
 
+
Import the AAR file into your existing AndroidStudio as a new module and update your project and app .gradle files to include the new module.
+
 
+
[http://dev.socialidnow.com/index.php/Android_SDK_Download Download the SDK]
+
 
+
= Get your Social-ID data =
+
  
 
You'll need 3 variables to configure the SDK:
 
You'll need 3 variables to configure the SDK:
  
 
* SENDER_ID: Set up a project on Google Developers Console - https://console.developers.google.com/project. Get your project number. This will be used as the SENDER_ID in the SDK.
 
* SENDER_ID: Set up a project on Google Developers Console - https://console.developers.google.com/project. Get your project number. This will be used as the SENDER_ID in the SDK.
* LOGIN_APP_ID: Set up a Social-ID LoginApp at: https://app.socialidnow.com/marketing/login/apps. Your key is the id of the app. This will be used as the LOGIN_APP_ID in the SDK.
+
* LOGIN_APP_ID: Set up a CoffeeBean LoginApp at: https://app.socialidnow.com/marketing/login/apps. Your key is the id of the app. This will be used as the LOGIN_APP_ID in the SDK.
 
* LOGIN_APP_CLIENT_SECRET: The client secret can be found on the Call the API menu - https://app.socialidnow.com/marketing/login/apps/APP_ID/apis. This will be used as the LOGIN_APP_CLIENT_SECRET in the SDK.
 
* LOGIN_APP_CLIENT_SECRET: The client secret can be found on the Call the API menu - https://app.socialidnow.com/marketing/login/apps/APP_ID/apis. This will be used as the LOGIN_APP_CLIENT_SECRET in the SDK.
  
= Add the SDK to your app =
+
== Download the SDK ==  
  
Add the following import statements to your Activity:
+
[[Android_SDK_Download|Download the SDK]]
  
  import com.coffeebeantech.socialidsdk.SocialId;
+
Import the AAR file into your existing AndroidStudio as a new module and update your project and app .gradle files to include the new module.
  import com.coffeebeantech.socialidsdk.notification.NotificationParameters;
+
  
Call SocialId.config from the onCreate method of your Activity class to set your application Social-ID configuration:
+
Project ''settings.gradle'' file:
  
   SocialId.config(this, "SENDER_ID", "LOGIN_APP_ID", "LOGIN_APP_CLIENT_SECRET");
+
   include ':socialidsdk'
  
Add the following variable to the ''res/values/strings.xml'' file:
+
App specific ''app/build.gradle'' file:
  <!-- Facebook App ID -->
+
  <string name="app_id">FACEBOOK_APP_ID</string>
+
  
Add the following content to the ''assets/oauth_consumer.properties'' file. Ensure the ''assets'' folder is at the same level as the ''res'' folder.
+
  dependencies {
  #twitter
+
    implementation project(':socialidsdk')
  twitter.com.consumer_key = TWITTER_CONSUMER_KEY
+
   }
  twitter.com.consumer_secret = TWITTER_CONSUMER_SECRET
+
 
+
  #linkedin
+
  api.linkedin.com.consumer_key = LINKEDIN_CLIENT_ID
+
   api.linkedin.com.consumer_secret = LINKEDIN_CLIENT_SECRET
+
  
= Modify app manifest =
+
== Android Manifest ==
  
 
Add the following definitions to AndroidManifest.xml immediately before opening the ''<application>'' tag:
 
Add the following definitions to AndroidManifest.xml immediately before opening the ''<application>'' tag:
  
 
   <uses-permission android:name="android.permission.INTERNET" />
 
   <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
 
 
   <uses-permission android:name="android.permission.USE_CREDENTIALS" />
 
   <uses-permission android:name="android.permission.USE_CREDENTIALS" />
 
    
 
    
Line 50: Line 35:
 
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <permission
 
      android:name="com.YOUR_PACKAGE.C2D_MESSAGE"
 
      android:protectionLevel="signature" />   
 
 
   <uses-permission android:name="com.YOUR_PACKAGE.C2D_MESSAGE" />
 
   <uses-permission android:name="com.YOUR_PACKAGE.C2D_MESSAGE" />
 
   <nowiki><!-- END: use this if you need push notification support --></nowiki>
 
   <nowiki><!-- END: use this if you need push notification support --></nowiki>
Line 58: Line 40:
 
Add the following definitions to AndroidManifest.xml inside the ''<application>'' tag:
 
Add the following definitions to AndroidManifest.xml inside the ''<application>'' tag:
  
  <meta-data
 
      android:name="com.google.android.gms.version"
 
      android:value="@integer/google_play_services_version" />
 
  <meta-data
 
      android:name="com.facebook.sdk.ApplicationId"
 
      android:value="@string/app_id" />
 
  <activity android:name="com.facebook.LoginActivity" >
 
  </activity>
 
 
 
 
   <nowiki><!-- BEGIN: use this if you need push notification support --></nowiki>
 
   <nowiki><!-- BEGIN: use this if you need push notification support --></nowiki>
 
   <receiver
 
   <receiver
Line 87: Line 60:
 
   <service android:name="com.coffeebeantech.socialidsdk.registration.RegistrationService" />
 
   <service android:name="com.coffeebeantech.socialidsdk.registration.RegistrationService" />
 
   <nowiki><!-- END: use this if you need push notification support --></nowiki>
 
   <nowiki><!-- END: use this if you need push notification support --></nowiki>
 +
 +
== Resources ==
 +
 +
Add the following variables to your resources file:
 +
 +
  <nowiki><!-- Social Id configuration --></nowiki>
 +
  <string name="login_app_id">LOGIN_APP_ID</string>;
 +
  <string name="login_app_client_secret">LOGIN_APP_CLIENT_SECRET</string>;
 +
 
 +
  <nowiki><!-- Google Project Number (if you need push notification support) --></nowiki>
 +
  <string name="sender_id">SENDER_ID</string>;
 +
 +
== Usage ==
 +
 +
Add the following import statements to your Activity:
 +
 +
  import com.coffeebeantech.socialidsdk.SocialId;
 +
  import com.coffeebeantech.socialidsdk.notification.NotificationParameters;
 +
 +
At your Activity onCreate method, call SocialId.configLoginProviders with the desired providers configuration and then call SocialId.config to set your Social-ID configuration using the resources set before:
 +
 
 +
  // pass the providers configuration that will be set
 +
  SocialId.configLoginProviders(facebookConfiguration, gplusConfiguration, linkedinConfiguration, twitterConfiguration, emailConfiguration);
 +
 
 +
  // with push notifications support
 +
  SocialId.config(this, "SENDER_ID", "LOGIN_APP_ID", "LOGIN_APP_CLIENT_SECRET");
 +
  // without push notifications support
 +
  SocialId.config(this, "LOGIN_APP_ID", "LOGIN_APP_CLIENT_SECRET");
 +
 +
= Add Facebook Login to your app =
 +
 +
Before starting to add the Facebook SDK, you must allow your Facebook App to receive requests from your Android project.
 +
 +
* At the Facebook for developers page, find your Facebook App at [https://developers.facebook.com/apps/ My Apps]
 +
* Go to Settings > Basic
 +
* At the end of page click on "Add a Platform" and then select "Android"
 +
* Add your project package name at "Google Play Package Name" and your default activity class name at "Class Name"
 +
* Export your Development Key Hash using the instructions for your operating system, add the exported key to "Key Hashes" and then "Save Changes" to proceed to next steps
 +
: MacOS
 +
  $ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64
 +
: Windows
 +
: You need the folowing:
 +
:* Key and Certificate Management Tool ('''keytool''') from the Java Development Kit
 +
:* [https://code.google.com/archive/p/openssl-for-windows/downloads openssl-for-windows] openssl library for Windows from the Google Code Archive
 +
  $ keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64
 +
 +
Add the Facebook maven repository to your ''app/build.gradle'' before the ''dependencies'' area and add the latest Facebook SDK dependency to your list of dependencies:
 +
 +
  repositories {
 +
    mavenCentral()
 +
  }
 +
 
 +
  dependencies {
 +
    implementation 'com.facebook.android:facebook-android-sdk:4.40.0'
 +
  }
 +
 +
== Android Manifest ==
 +
 +
Add the Facebook ApplicationId that will be used in your AndroidManifest.xml inside the <application> tag as following:
 +
 +
  <meta-data
 +
    android:name="com.facebook.sdk.ApplicationId"
 +
    android:value="@string/facebook_app_id" />
 +
 
 +
  <nowiki><!-- If you want to make changes to the Facebook Login Activity you can do changes using the tag below --></nowiki>
 +
  <activity android:name="com.facebook.FacebookActivity"
 +
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
 +
    android:label="@string/app_name" />
 +
  </activity>
 +
 +
== Resources ==
 +
 +
Add the following variables to your resources file:
 +
 +
  <!-- Facebook App ID -->
 +
  <string name="facebook_app_id">FACEBOOK_APP_ID</string>
 +
 
 +
  <string-array name="facebook_permissions">
 +
      <item>public_profile</item>
 +
      <item>user_birthday</item>
 +
      <item>email</item>
 +
      <item>user_location</item>
 +
  </string-array>
 +
 +
== Usage ==
 +
 +
Initializes a new Facebook configuration and set the permissions:
 +
 +
  // Facebook configuration
 +
  FacebookConfiguration facebookConfiguration = new FacebookConfiguration()
 +
      .setPermissions("FACEBOOK_PERMISSIONS");
 +
 +
= Add Twitter Login to your app =
 +
 +
Add the '''twittersdk://''' to your [https://developer.twitter.com/en/apps Twitter App] Callback URLs to allow an Android project to use it.
 +
 +
Add the Twitter JCenter repository to your app/build.gradle before the dependencies area and add the Twitter SDK dependency to your list of dependencies:
 +
 +
  repositories {
 +
    jcenter()
 +
  }
 +
 
 +
  dependencies {
 +
    implementation('com.twitter.sdk.android:twitter:3.1.1') {
 +
      transitive = true;
 +
    }
 +
  }
 +
 +
== Resources ==
 +
 +
  <!-- Twitter Credentials -->
 +
  <string name="twitter_key">TWITTER_KEY</string>
 +
  <string name="twitter_secret">TWITTER_SECRET</string>
 +
 +
== Usage ==
 +
 +
Initializes a new Twitter configuration and set the credentials:
 +
 +
  // Twitter configuration
 +
  TwitterConfiguration twitterConfiguration = new TwitterConfiguration()
 +
      .setTwitterKey("TWITTER_KEY")
 +
      .setTwitterSecret("TWITTER_SECRET");
 +
 +
 +
= Add Google Login to your app =
 +
 +
To add the Google Login to your Android project you must:
 +
 +
* Have an Android and a Web Application "OAuth client ID" [https://console.developers.google.com/apis/credentials Credentials]
 +
** The Android Credential must be set with the SHA1 signing-certificate fingerprint and the Package Name to the Login with Google work.
 +
 +
Example to export the SHA1 from the debug key:
 +
  $ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v
 +
 +
 +
Add the latest Google GCM and Auth SDK dependency to your list of dependencies:
 +
 +
  dependencies {
 +
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
 +
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
 +
  }
 +
 +
== Resources ==
 +
 +
Add the Client ID from the created Web Application credential  to your resources file:
 +
  <nowiki><!-- Google Client Server ID --></nowiki>
 +
  <string name="google_client_server_id">"WEB_APPLICATION_CLIENT_ID"</string>;
 +
 +
== Usage ==
 +
 +
Initializes a new Gplus configuration and set the client server id with the Web Application client ID:
 +
  // Google+ configuration
 +
  GplusConfiguration gplusConfiguration = new GplusConfiguration()
 +
      .setClientServerId("WEB_APPLICATION_CLIENT_ID"));
 +
 +
= Add Linkedin Login to your app =
 +
 +
Add the following content to the ''assets/oauth_consumer.properties'' file. Custom Permissions must be a single string split by a comma (ex: r_liteprofile,r_emailaddress). Ensure the ''assets'' folder is at the same level as the ''res'' folder.
 +
  #linkedin
 +
  api.linkedin.com.consumer_key = LINKEDIN_CLIENT_ID
 +
  api.linkedin.com.consumer_secret = LINKEDIN_CLIENT_SECRET
 +
  api.linkedin.com.custom_permissions = LINKEDIN_PERMISSIONS
 +
 +
== Resources ==
 +
 +
Add the Linkedin Callback URI to your resources file:
 +
 +
  <nowiki><!-- Linkedin Callback URI --></nowiki>
 +
  <string name="linkedin_callback_uri">LINKEDIN_CALLBACK_URI</string>
 +
 +
== Usage ==
 +
 +
Initializes a new Linkedin configuration and set the callback uri:
 +
 +
  // LinkedIn configuration
 +
  LinkedinConfiguration linkedinConfiguration = new LinkedinConfiguration()
 +
      .setCallbackUri("LINKEDIN_CALLBACK_URI");

Latest revision as of 17:25, 20 August 2019

Contents

Configure CoffeeBean SDK in your app

You'll need 3 variables to configure the SDK:

Download the SDK

Download the SDK

Import the AAR file into your existing AndroidStudio as a new module and update your project and app .gradle files to include the new module.

Project settings.gradle file:

 include ':socialidsdk'

App specific app/build.gradle file:

 dependencies {
   implementation project(':socialidsdk')
 }

Android Manifest

Add the following definitions to AndroidManifest.xml immediately before opening the <application> tag:

 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.USE_CREDENTIALS" />
 
 <!-- BEGIN: use this if you need push notification support -->
 <uses-permission android:name="android.permission.WAKE_LOCK" />
 <uses-permission android:name="android.permission.VIBRATE" />
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <uses-permission android:name="com.YOUR_PACKAGE.C2D_MESSAGE" />
 <!-- END: use this if you need push notification support -->

Add the following definitions to AndroidManifest.xml inside the <application> tag:

 <!-- BEGIN: use this if you need push notification support -->
 <receiver
     android:name="com.coffeebeantech.socialidsdk.notification.NotificationReceiver"
     android:permission="com.google.android.c2dm.permission.SEND" >
     <intent-filter>
         <action android:name="com.google.android.c2dm.intent.RECEIVE" />
         <category android:name="com.YOUR_PACKAGE" />
     </intent-filter>
 </receiver>
 <receiver
     android:name="com.coffeebeantech.socialidsdk.registration.ConnectivityMonitor"
     android:enabled="false" >
     <intent-filter>
         <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
         <category android:name="com.YOUR_PACKAGE" />
     </intent-filter>
 </receiver>
 <service android:name="com.coffeebeantech.socialidsdk.notification.NotificationService" />
 <service android:name="com.coffeebeantech.socialidsdk.registration.RegistrationService" />
 <!-- END: use this if you need push notification support -->

Resources

Add the following variables to your resources file:

 <!-- Social Id configuration -->
 <string name="login_app_id">LOGIN_APP_ID</string>;
 <string name="login_app_client_secret">LOGIN_APP_CLIENT_SECRET</string>;
 
 <!-- Google Project Number (if you need push notification support) -->
 <string name="sender_id">SENDER_ID</string>;

Usage

Add the following import statements to your Activity:

 import com.coffeebeantech.socialidsdk.SocialId;
 import com.coffeebeantech.socialidsdk.notification.NotificationParameters;

At your Activity onCreate method, call SocialId.configLoginProviders with the desired providers configuration and then call SocialId.config to set your Social-ID configuration using the resources set before:

 // pass the providers configuration that will be set
 SocialId.configLoginProviders(facebookConfiguration, gplusConfiguration, linkedinConfiguration, twitterConfiguration, emailConfiguration);
 
 // with push notifications support
 SocialId.config(this, "SENDER_ID", "LOGIN_APP_ID", "LOGIN_APP_CLIENT_SECRET");
 // without push notifications support
 SocialId.config(this, "LOGIN_APP_ID", "LOGIN_APP_CLIENT_SECRET");

Add Facebook Login to your app

Before starting to add the Facebook SDK, you must allow your Facebook App to receive requests from your Android project.

  • At the Facebook for developers page, find your Facebook App at My Apps
  • Go to Settings > Basic
  • At the end of page click on "Add a Platform" and then select "Android"
  • Add your project package name at "Google Play Package Name" and your default activity class name at "Class Name"
  • Export your Development Key Hash using the instructions for your operating system, add the exported key to "Key Hashes" and then "Save Changes" to proceed to next steps
MacOS
 $ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 
Windows
You need the folowing:
  • Key and Certificate Management Tool (keytool) from the Java Development Kit
  • openssl-for-windows openssl library for Windows from the Google Code Archive
 $ keytool -exportcert -alias androiddebugkey -keystore "C:\Users\USERNAME\.android\debug.keystore" | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" sha1 -binary | "PATH_TO_OPENSSL_LIBRARY\bin\openssl" base64

Add the Facebook maven repository to your app/build.gradle before the dependencies area and add the latest Facebook SDK dependency to your list of dependencies:

 repositories {
   mavenCentral() 
 }
 
 dependencies { 
   implementation 'com.facebook.android:facebook-android-sdk:4.40.0'
 }

Android Manifest

Add the Facebook ApplicationId that will be used in your AndroidManifest.xml inside the <application> tag as following:

 <meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id" />
 
 <!-- If you want to make changes to the Facebook Login Activity you can do changes using the tag below -->
 <activity android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name" />
 </activity>

Resources

Add the following variables to your resources file:

 <string name="facebook_app_id">FACEBOOK_APP_ID</string>
 
 <string-array name="facebook_permissions">
     <item>public_profile</item>
     <item>user_birthday</item>
     <item>email</item>
     <item>user_location</item>
 </string-array>

Usage

Initializes a new Facebook configuration and set the permissions:

 // Facebook configuration
 FacebookConfiguration facebookConfiguration = new FacebookConfiguration()
     .setPermissions("FACEBOOK_PERMISSIONS");

Add Twitter Login to your app

Add the twittersdk:// to your Twitter App Callback URLs to allow an Android project to use it.

Add the Twitter JCenter repository to your app/build.gradle before the dependencies area and add the Twitter SDK dependency to your list of dependencies:

 repositories {
   jcenter()
 }
 
 dependencies {
   implementation('com.twitter.sdk.android:twitter:3.1.1') {
     transitive = true;
   }
 }

Resources

 <string name="twitter_key">TWITTER_KEY</string>
 <string name="twitter_secret">TWITTER_SECRET</string>

Usage

Initializes a new Twitter configuration and set the credentials:

 // Twitter configuration
 TwitterConfiguration twitterConfiguration = new TwitterConfiguration()
     .setTwitterKey("TWITTER_KEY")
     .setTwitterSecret("TWITTER_SECRET");


Add Google Login to your app

To add the Google Login to your Android project you must:

  • Have an Android and a Web Application "OAuth client ID" Credentials
    • The Android Credential must be set with the SHA1 signing-certificate fingerprint and the Package Name to the Login with Google work.

Example to export the SHA1 from the debug key:

 $ keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v


Add the latest Google GCM and Auth SDK dependency to your list of dependencies:

 dependencies {
   implementation 'com.google.android.gms:play-services-gcm:16.0.0'
   implementation 'com.google.android.gms:play-services-auth:16.0.1'
 }

Resources

Add the Client ID from the created Web Application credential to your resources file:

 <!-- Google Client Server ID -->
 <string name="google_client_server_id">"WEB_APPLICATION_CLIENT_ID"</string>; 

Usage

Initializes a new Gplus configuration and set the client server id with the Web Application client ID:

 // Google+ configuration
 GplusConfiguration gplusConfiguration = new GplusConfiguration()
     .setClientServerId("WEB_APPLICATION_CLIENT_ID"));

Add Linkedin Login to your app

Add the following content to the assets/oauth_consumer.properties file. Custom Permissions must be a single string split by a comma (ex: r_liteprofile,r_emailaddress). Ensure the assets folder is at the same level as the res folder.

 #linkedin
 api.linkedin.com.consumer_key = LINKEDIN_CLIENT_ID
 api.linkedin.com.consumer_secret = LINKEDIN_CLIENT_SECRET
 api.linkedin.com.custom_permissions = LINKEDIN_PERMISSIONS 

Resources

Add the Linkedin Callback URI to your resources file:

 <!-- Linkedin Callback URI -->
 <string name="linkedin_callback_uri">LINKEDIN_CALLBACK_URI</string>

Usage

Initializes a new Linkedin configuration and set the callback uri:

 // LinkedIn configuration
 LinkedinConfiguration linkedinConfiguration = new LinkedinConfiguration()
     .setCallbackUri("LINKEDIN_CALLBACK_URI");
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox