Skip to content

george-sp/firebase-android-udacity

Repository files navigation

firebase-android-udacity

Code repository for Udacity's Firebase in a Weekend: Android course

Set-Up

A new Firebase project is required. Go to firebase.google.com.

Realtime Database

Data

{
    "messages" : {
        "-KdqgvFEYzj3zQEh2W4b" : {
            "name" : "user_1",
            "text" : "hello!"
        },
        "-KdqtFtHUFCnUIfjRK-c" : {
            "name" : "user_2",
            "text" : "hi!"
        }
    }
}

Rules

{
    "rules": {
        "messages" : {
            // only authenticated users can read and write the messages node
            ".read": "auth != null",
            ".write": "auth != null",
                "$id": {
                    // the read and write rules cascade to the individual messages
                    // messages should have a 'name' and a 'text' key or a 'name' and 'photoUrl' key
                    ".validate": "newData.hasChildren(['name', 'text']) && !newData.hasChildren(['photoUrl']) || newData.hasChildren(['name', 'photoUrl']) && !newData.hasChildren(['text'])"
                }
          }
    }
}

Check out Firebase Realtime Database Security Documentation for more information.

Storage

Files

Create a folder called chat_photos in the Storage dashboard of Firebase Cosole.

Rules

service firebase.storage {
    match /b/friendlychat-c780d.appspot.com/o {
        match /{imageId=**} {
            allow read: if request.auth != null;
            allow write: if request.auth != null && request.resource.size < 3 * 1024 * 1024;
        }
    }
}

Check out Firebase Storage Security Documentation and Firebase Storage Security Rules Reference for more information.

Authentication

Notifications

Steps

  1. Add the gradle dependency for messaging
  2. Go to the Notifications tab in the Firebase Console
  3. Create your own message to send as notification
  4. Send the notification *
  5. See the notification on your Android device

* Make sure that the app is in the background before sending the notifiaction

Remote Config

Key Capabilities

  • Quickly roll out changes to your app's userbase
  • Customize your app for segments of your userbase
  • Run A/B tests to improve your app

Implementation Path

  1. Instrument your app wiith Remote Config
  2. Set default parameter values
  3. Add logic to fetch, activate and get parameter values
  4. Update service-side default and conditional parameter values

Check out Firebase Remote Config docs for more information.

Notes on Security (Realtime Database vs Storage)

  • Firebase Storage Security rule types: read, write

  • Firebase Realtime Database rule types: .read, .write, .validate


  • Firebase Storage Security rules are not cascading (A value of true for a parent doesn't cause all children to be true.)

  • Firebase Realtime Database rules are cascading for .read and .write (A value of true for a parent applies all children below the point where the node was declared true.)

About

Code repository for Udacity's "Firebase in a Weekend(Android)" course - https://www.udacity.com/course/firebase-in-a-weekend-by-google-android--ud0352

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages