Android Apps Development Workshop Day 2 slides
Transcript of Android Apps Development Workshop Day 2 slides
• Full Stack Android Developer
• Top Rated Freelancer on Upwork
• Founder SumatoDev.com (The Mobile Apps Development Agency)
• 5+ years of experience developing Android Apps
• Most recent app is Hash-Todo Task Management App developed with Firebase
Shajeel Afzal
@ShajeelAfzal ShajeelAfzal.com
SumatoDev.com
I will be covering
• Facebook Login with Facebook Android SDK
• Firebase Basics
• Authentication with Firebase
• Saving and showing data from Firebase
• In App Purchase Integration
How it Works?
• Facebook Android SDK provides easy way to Login
• Users can grant permissions to our app
• Permissions like user_friends, email, user_posts etc
Read more about Permissions at https://goo.gl/rnBVav
Getting Facebook App ID
https://developers.facebook.com/quickstarts/?platform=android
AccessTracker
• Create instance in the BaseActivity
• Callback method “onCurrentAccessTokenChanged”
• if(currentAccessToken != null)
• User is Logged In
• else
• User Logged Out.
Firebase Introduction• NoSQL (key-value) based database
• Provides easy authentication methods
• Easy to write security rules to control security
• Automatically handles integration with Facebook, Google, Twitter, GitHub, Custom Provider and even Anonymous Login.
• Comes with builtin offline support
• No need to write “AsyncTasks” to store and retrieve data
• No need to worry about server side (Almost)
Firebase Authentication• Create Account on firebase.com
• Create New Project
• Enable Facebook Provider for the project by giving Facebook “App ID” and Facebook “App Secret”
• Specify the “Session Length”
• Include the Firebase-Android-SDK
• Initialise the SDK and use “authWithOAuthToken” method by passing the Facebook access token
Firebase Authentication• public void onAuthenticated(AuthData authData) is
called if authentication is successful
• public void onAuthenticationError(FirebaseError firebaseError) is called if not
• authData contains all the information of the authenticated user like UID, profile picture url, user name etc.
• NOTE: Authentication does not mean that user is created on Firebase
https://www.firebase.com/docs/android/guide/user-auth.html
Save User on Firebase
• Let’s discuss how we will organise the data
• Let’s discuss how Hash-Todo app organises the data
• Create User model
• Extract all user information from the AuthData object (I have created helper method for that)
• Store the user object on Firebase
Firebase usersRef = mFirebaseRef.child(Constants.FIREBASE_LOCATION_USERS).child(authData.getUid()); usersRef.setValue(user, new Firebase.CompletionListener() { @Override public void onComplete(FirebaseError firebaseError, Firebase firebase) { if (firebaseError == null) { } else { DialogUtils.showOkDialog(BaseActivity.this, "Login Problem", "Sorry an error occurred while logging in."); } }});