Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

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

9.972 Aufrufe

Veröffentlicht am

Slides used in Google I/O Extended Bangkok 2016 session

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

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

  1. 1. Introduction to
  2. 2. #GeekAlert
  3. 3. #teamFirebase
  4. 4. To develop a mobile application What people think
  5. 5. To develop a mobile application Reality
  6. 6. To develop a mobile application Reality Authentication Database Storage Analytics Crash Reporting Push Notifications Web Hosting etc.
  7. 7. To develop a mobile application Reality Authentication Database Storage Analytics Crash Reporting Push Notifications Web Hosting etc.
  8. 8. 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_)@
  9. 9. …@()$*!)@JHO(@)$#(!I_)@
  10. 10. To develop a mobile application Reality Authentication Database Storage Analytics Crash Reporting Push Notifications Web Hosting etc.
  11. 11. To develop a mobile application Authentication Database Storage Analytics Crash Reporting Push Notifications Web Hosting etc.
  12. 12. To develop a mobile application
  13. 13. To develop a mobile application REST? REST?
  14. 14. To develop a mobile application Android SDK iOS SDK
  15. 15. With Firebase • Compact team: You don’t need to hire Backend engineers • Fast iteration • Scalable • Your team can sleep at night !
  16. 16. Realtime Database Authentication Hosting
  17. 17. Here comes the new
  18. 18. 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
  19. 19. Easy to read documentation
  20. 20. Firebase: Get Started
  21. 21. Firebase • Strongly Integrated with Android Studio 2.2 • You can integrate Firebase with your app with just few clicks ! • [Live Demo]
  22. 22. Authentication • Register / Login with • Email + Password • Google • Facebook • Twitter • GitHub • Email address verification • Password reset
  23. 23. Authentication private FirebaseAuth mAuth; //... mAuth = FirebaseAuth.getInstance();
  24. 24. 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(); } // ... } });
  25. 25. 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(); } // ... } });
  26. 26. Sign Out FirebaseAuth.getInstance().signOut();
  27. 27. 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){} });
  28. 28. 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(); } // ... } }); }
  29. 29. Realtime Database • Cloud-hosted NoSQL database • Synchronization & conflict resolution • Access directly from your app
  30. 30. Realtime Database
  31. 31. Realtime Database //Write a message to the database FirebaseDatabase database = FirebaseDatabase.getInstance(); DatabaseReference myRef= database.getReference("message"); myRef.setValue("Hello, World!");
  32. 32. 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()); } });
  33. 33. Storage • Easy file storage • Handles poor connectivity • Backed by & accessible from Google Cloud Storage
  34. 34. Storage FirebaseStoragestorage=FirebaseStorage.getInstance();
  35. 35. 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(); } });
  36. 36. 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 } });
  37. 37. Hosting • Serve static assets • SSL by default
  38. 38. Hosting Install the Firebase CLI npminstall –g firebase-tools Initialize your app $firebaseinit Add a file Deploy your website $firebasedeploy
  39. 39. Hosting Install the Firebase CLI npminstall –g firebase-tools Initialize your app $firebaseinit Add a file Deploy your website $firebasedeploy
  40. 40. Remote Config • Dynamically configures your app on-the-fly • [Live Demo]
  41. 41. 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
  42. 42. 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
  43. 43. 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
  44. 44. Crash Reporting • See crashes & impact • Version & OS drill-down • Integrated with Analytics
  45. 45. 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'
  46. 46. Test Lab • Test on the most popular devices before you ship • Reports & screenshots • Robo & custom tests
  47. 47. Test Lab In Action
  48. 48. 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
  49. 49. Dynamic Links • Customize different user experiences via a single URL • Works across platforms • Preserves URL state, even through app install flow • Analytics insights
  50. 50. Invites • Drop-in widget for app sharing • Supports SMS and Email • Recipient suggestions from Google • Built on Dynamic Links
  51. 51. Invites
  52. 52. 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); }
  53. 53. 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 //... } } }
  54. 54. App Indexing • Integrate with Google Search • Index app content • Boost search ranking
  55. 55. App Indexing
  56. 56. AdMob by Google • Engaging formats: video, interstitial & native • 1M+ apps using AdMob • Integrated with Firebase SDK
  57. 57. Analytics • Designed for apps • Event and user centric • Connects across Firebase
  58. 58. Pricing
  59. 59. 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
  60. 60. Thank you

×