Introduction to Firebase [Google I/O Extended Bangkok 2016]
- 6. To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
- 7. To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
- 11. To develop a mobile application
Reality
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
- 12. To develop a mobile application
Authentication
Database
Storage
Analytics
Crash Reporting
Push Notifications
Web Hosting
etc.
- 16. With Firebase
• Compact team: You don’t need to hire Backend engineers
• Fast iteration
• Scalable
• Your team can sleep at night !
- 26. Authentication
• Register / Login with
• Email + Password
• Google
• Facebook
• Twitter
• GitHub
• Email address verification
• Password reset
- 32. 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();
}
// ...
}
});
}
- 35. Realtime Database
//Write a message to the database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef= database.getReference("message");
myRef.setValue("Hello, World!");
- 37. Storage
• Easy file storage
• Handles poor connectivity
• Backed by & accessible from
Google Cloud Storage
- 39. 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();
}
});
- 40. 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
}
});
- 42. Hosting
Install the Firebase CLI
npminstall –g firebase-tools
Initialize your app
$firebaseinit
Add a file
Deploy your website
$firebasedeploy
- 43. Hosting
Install the Firebase CLI
npminstall –g firebase-tools
Initialize your app
$firebaseinit
Add a file
Deploy your website
$firebasedeploy
- 47. 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
- 53. Test Lab
• Test on the most popular
devices before you ship
• Reports & screenshots
• Robo & custom tests
- 59. Dynamic Links
• Customize different user experiences
via a single URL
• Works across platforms
• Preserves URL state, even through
app install flow
• Analytics insights
- 62. Invites
• Drop-in widget for app sharing
• Supports SMS and Email
• Recipient suggestions from Google
• Built on Dynamic Links
- 64. 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);
}
- 68. AdMob by Google
• Engaging formats:
video, interstitial & native
• 1M+ apps using AdMob
• Integrated with Firebase SDK