SlideShare a Scribd company logo
Introduction to
#GeekAlert
#teamFirebase
To develop a mobile application
What people think
To develop a mobile application
Reality
To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
To develop a mobile application
Backend Developer 1
System Admin
Backend Developer 2
@()$*!)@JHO(@)$#(!I_)@
…@()$*!)@JHO(@)$#(!I_)@
Introduction to Firebase [Google I/O Extended Bangkok 2016]
To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
To develop a mobile application
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
To develop a mobile application
To develop a mobile application
REST? REST?
To develop a mobile application
Android SDK iOS SDK
With Firebase
• Compact team: You don’t need to hire Backend engineers
• Fast iteration
• Scalable
• Your team can sleep at night !
Realtime Database
Authentication
Hosting
Here comes the new
DEVELOP
GROW
EARN
Backend Services
Realtime Database
Authentication
Hosting
Storage
Cloud Messaging
Remote Config
App Quality Services
Test Lab for Android
Crash Reporting
Acquisition
Dynamic Links
Invites
AdWords
Re-Engagement
Notifications
App Indexing
In-app Ads
AdMob
Analytics
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Easy to read documentation
Firebase: Get Started
Firebase
• Strongly Integrated with Android Studio 2.2
• You can integrate Firebase with your app with just few clicks !
• [Live Demo]
Authentication
• Register / Login with
• Email + Password
• Google
• Facebook
• Twitter
• GitHub
• Email address verification
• Password reset
Authentication
private FirebaseAuth mAuth;
//...
mAuth = FirebaseAuth.getInstance();
Creating User
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
if (!task.isSuccessful()) {
Toast.makeText(EmailPasswordActivity.this,
"Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
Logging In
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, “signInWithEmail:onComplete:" + task.isSuccessful());
if (!task.isSuccessful()) {
Toast.makeText(EmailPasswordActivity.this,
"Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
Sign Out
FirebaseAuth.getInstance().signOut();
Facebook Login
mCallbackManager =CallbackManager.Factory.create();
LoginButtonloginButton=(LoginButton)findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email","public_profile");
loginButton.registerCallback(mCallbackManager,newFacebookCallback<LoginResult>(){
@Override
publicvoidonSuccess(LoginResultloginResult){
Log.d(TAG,"facebook:onSuccess:"+loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
publicvoidonCancel(){}
@Override
publicvoidonError(FacebookExceptionerror){}
});
Facebook Login
privatevoidhandleFacebookAccessToken(AccessTokentoken){
Log.d(TAG, "handleFacebookAccessToken:"+ token);
AuthCredentialcredential= FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this,new OnCompleteListener<AuthResult>(){
@Override
publicvoidonComplete(@NonNullTask<AuthResult>task) {
Log.d(TAG, "signInWithCredential:onComplete:"+ task.isSuccessful());
// If signin fails, displayamessageto the user.If signin succeeds
// theauthstatelistenerwill benotifiedandlogic tohandlethe
// signedin usercan be handledin the listener.
if (!task.isSuccessful()){
Log.w(TAG, "signInWithCredential",task.getException());
Toast.makeText(FacebookLoginActivity.this,"Authenticationfailed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
Realtime Database
• Cloud-hosted NoSQL database
• Synchronization & conflict resolution
• Access directly from your app
Realtime Database
Realtime Database
//Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef= database.getReference("message");
myRef.setValue("Hello, World!");
Realtime Database
//Readfromthedatabase
myRef.addValueEventListener(newValueEventListener(){
@Override
publicvoidonDataChange(DataSnapshotdataSnapshot){
//Thismethodiscalledonce withtheinitialvalueand again
//wheneverdataatthislocationisupdated.
Stringvalue= dataSnapshot.getValue(String.class);
Log.d(TAG,"Valueis:" + value);
}
@Override
publicvoidonCancelled(DatabaseErrorerror){
//Failedtoreadvalue
Log.w(TAG,"Failedtoreadvalue.",error.toException());
}
});
Storage
• Easy file storage
• Handles poor connectivity
• Backed by & accessible from
Google Cloud Storage
Storage
FirebaseStoragestorage=FirebaseStorage.getInstance();
Uploading a file
Urifile= Uri.fromFile(newFile("path/to/images/rivers.jpg"));
StorageReferenceriversRef= storageRef.child("images/"+file.getLastPathSegment());
uploadTask= riversRef.putFile(file);
//Registerobserverstolistenforwhenthedownloadisdoneorifitfails
uploadTask.addOnFailureListener(newOnFailureListener(){
@Override
publicvoidonFailure(@NonNullException exception){
//Handleunsuccessfuluploads
}
}).addOnSuccessListener(newOnSuccessListener<UploadTask.TaskSnapshot>(){
@Override
publicvoidonSuccess(UploadTask.TaskSnapshottaskSnapshot){
//taskSnapshot.getMetadata()containsfilemetadatasuch assize,
//content-type,anddownloadURL.
UridownloadUrl= taskSnapshot.getDownloadUrl();
}
});
Downloading a file
islandRef= storageRef.child("images/island.jpg");
File localFile= File.createTempFile("images","jpg");
islandRef.getFile(localFile)
.addOnSuccessListener(newOnSuccessListener<FileDownloadTask.TaskSnapshot>(){
@Override
publicvoidonSuccess(FileDownloadTask.TaskSnapshottaskSnapshot){
//Localtempfile hasbeencreated
}
}).addOnFailureListener(newOnFailureListener(){
@Override
publicvoidonFailure(@NonNullException exception){
//Handleanyerrors
}
});
Hosting
• Serve static assets
• SSL by default
Hosting
Install the Firebase CLI
npminstall –g firebase-tools
Initialize your app
$firebaseinit
Add a file
Deploy your website
$firebasedeploy
Hosting
Install the Firebase CLI
npminstall –g firebase-tools
Initialize your app
$firebaseinit
Add a file
Deploy your website
$firebasedeploy
Remote Config
• Dynamically configures
your app on-the-fly
• [Live Demo]
Remote Config
mFirebaseRemoteConfig=FirebaseRemoteConfig.getInstance();
Set default parameter value as a XML file in res/xml
Fetch new configurations with fetch() and replace the current one
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Cloud Messaging
• Firebase Cloud Messaging (FCM)
• Enable Push Notifications in just few LoCs
• Build on top of GCM, switch to FCM !
• See in details in the next session
Introduction to Firebase [Google I/O Extended Bangkok 2016]
DEVELOP
GROW
EARN
Backend Services
Realtime Database
Authentication
Hosting
Storage
Cloud Messaging
Remote Config
App Quality Services
Test Lab for Android
Crash Reporting
Acquisition
Dynamic Links
Invites
AdWords
Re-Engagement
Notifications
App Indexing
In-app Ads
AdMob
Analytics
Crash Reporting
• See crashes & impact
• Version & OS drill-down
• Integrated with Analytics
Crash Reporting
FirebaseCrash.report(new Exception("My first Android non-fatal error"));
FirebaseCrash.log("Activity created");
Basically just add dependency
compile 'com.google.firebase:firebase-crash:9.0.2'
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Test Lab
• Test on the most popular
devices before you ship
• Reports & screenshots
• Robo & custom tests
Test Lab
In Action
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
DEVELOP
GROW
EARN
Backend Services
Realtime Database
Authentication
Hosting
Storage
Cloud Messaging
Remote Config
App Quality Services
Test Lab for Android
Crash Reporting
Acquisition
Dynamic Links
Invites
AdWords
Re-Engagement
Notifications
App Indexing
In-app Ads
AdMob
Analytics
Dynamic Links
• Customize different user experiences
via a single URL
• Works across platforms
• Preserves URL state, even through
app install flow
• Analytics insights
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Invites
• Drop-in widget for app sharing
• Supports SMS and Email
• Recipient suggestions from Google
• Built on Dynamic Links
Invites
Invites
private voidonInviteClicked() {
Intent intent =new AppInviteInvitation
.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
}
Invites
@Override
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
super.onActivityResult(requestCode,resultCode,data);
Log.d(TAG,"onActivityResult:requestCode="+requestCode+ ",resultCode="+resultCode);
if(requestCode== REQUEST_INVITE){
if(resultCode==RESULT_OK){
//GettheinvitationIDsofallsentmessages
String[]ids= AppInviteInvitation.getInvitationIds(resultCode,data);
for(Stringid :ids){
Log.d(TAG, "onActivityResult:sentinvitation" + id);
}
}else {
//Sendingfailedoritwascanceled, showfailuremessagetotheuser
//...
}
}
}
App Indexing
• Integrate with Google Search
• Index app content
• Boost search ranking
App Indexing
AdMob by Google
• Engaging formats:
video, interstitial & native
• 1M+ apps using AdMob
• Integrated with Firebase SDK
Analytics
• Designed for apps
• Event and user centric
• Connects across Firebase
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Pricing
DEVELOP
GROW
EARN
Backend Services
Realtime Database
Authentication
Hosting
Storage
Cloud Messaging
Remote Config
App Quality Services
Test Lab for Android
Crash Reporting
Acquisition
Dynamic Links
Invites
AdWords
Re-Engagement
Notifications
App Indexing
In-app Ads
AdMob
Analytics
Thank you

More Related Content

Introduction to Firebase [Google I/O Extended Bangkok 2016]