Android SDK Setup
Contents |
Configure CoffeeBean SDK in your app
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.
- 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.
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");