Firebase Android Quickstart Samples

repository·master·Indexed 27 days ago

https://github.com/firebase/quickstart-android

A collection of Android quickstart samples demonstrating the integration of various Firebase APIs. Includes implementations for Firebase Authentication (Google, Facebook, Email/Password, Phone, Custom, and MFA), Cloud Functions, Remote Config, Crashlytics, Firebase Database, Google Analytics, App Distribution, and AdMob banner and interstitial ads.

Tokens
8.2K
Snippets
6
Records
49
Agent score
94%

What's inside firebase-quickstart-android

  1. Available Firebase Quickstart Samples

    master

    This repository contains individual sample projects for the following Firebase services:

    • Admob
    • Firebase AI Logic
    • Analytics
    • App Distribution
    • Auth
    • Remote Config
    • Crashlytics
    • Realtime Database
    • Data Connect
    • Firestore
    • Cloud Functions for Firebase
    • In-App Messaging
    • Cloud Messaging
    • Performance Monitoring
    • Cloud Storage for Firebase
  2. Understand the Firebase Database Data Model

    master

    This quickstart uses a social application data model with four root nodes designed for specific access patterns:

    • users: A list of User objects keyed by user ID (e.g., /users/<ID>/email).
    • posts: A list of Post objects keyed by a push ID. Each post contains uid and author properties. It also includes a stars map where /posts/<POST-ID>/stars/<USER-ID> is true if the user starred the post.
    • user-posts: A list of posts belonging to a specific user, keyed by user ID (/user-posts/<USER-ID>). This allows querying all posts by a user without scanning the entire posts tree.
    • post-comments: A list of comments for a specific post, keyed by post ID (/post-comments/<POST-ID>). This separation allows loading posts without fetching all associated comments.
  3. Quickstart: Firebase Remote Config for Android

    master

    The Firebase Remote Config Android quickstart demonstrates how to use Remote Config to override in-app default values by defining service-side parameter values in the Firebase console. This allows you to change user-facing text or app behavior without releasing a new version of the app.

    To use this sample:

    1. Add Firebase to your Android project.
    2. Create a Remote Config project in the Firebase console, defining the parameter keys and values used by the sample.
    3. Run the sample on an Android device or emulator.
    4. Change parameter values (e.g., welcome_message or welcome_message_caps) in the Firebase Console.
    5. Use the app's Fetch Remote Config feature to retrieve and apply the new values.
  4. Set up Passwordless (Email Link) Authentication

    master

    To enable passwordless sign-in via email links:

    1. In the Firebase Console, go to Auth > Sign In Method.
    2. Click Email/Password, turn on Enable, and then turn on the Email Link (passwordless sign-in) switch. Click Save.
    3. In your Android project, replace your-project-id in the AndroidManifest.xml file with your actual Firebase project ID.
    4. In the sample app, select PasswordlessActivity and click Send Link.
  5. Configure Firestore Security Rules for Friendly Eats

    master

    To allow the app to function correctly, add the following security rules to your Firestore project in the rules tab:

    • Restaurants: Anyone can read a restaurant. Only authenticated users can create or update restaurants. Deletions are prohibited.
    • Ratings: Anyone can read a rating. Authenticated users can create ratings. Only the user who created the rating can delete it. Ratings cannot be updated.
      match /databases/{database}/documents {
        // Anyone can read a restaurant, only authorized
        // users can create or update. Deletes are not allowed.
      	 match /restaurants/{restaurantId} {
        	 allow read: if true;
        	 allow create, update: if request.auth.uid != null;
        }
        
        // Anyone can read a rating. Only the user who made the rating
        // can delete it. Ratings can never be updated.
        match /restaurants/{restaurantId}/ratings/{ratingId} {
        	 allow read: if true;
          allow create: if request.auth.uid != null;
        	 allow delete: if request.resource.data.userId == request.auth.uid;
        	 allow update: if false;
        }
      }
    }
  6. Set in-app default parameter values

    master

    Before fetching values from the server, you should define in-app default values. This ensures your app has valid data even if the device is offline or the fetch fails.

    In this quickstart, defaults are set using an XML file, but you can also set them inline using the setDefault methods provided by the FirebaseRemoteConfig class.

  7. Initialize Data Connect via VS Code

    master
    1. Open the quickstart-android/dataconnect directory in Visual Studio Code.
    2. Open the Firebase Data Connect icon on the VS Code sidebar.
    3. Sign in with your Google Account.
    4. Click Connect a Firebase project and select your project.
    5. Click Start Emulators. This step automatically generates the Kotlin SDK and starts the local emulators.
  8. Set up Facebook Login

    master

    To enable Facebook Login, follow these steps:

    1. Meta for Developers Setup:
      • Create a new Android app at the Meta for Developers Site.
      • Use package name: com.google.firebase.quickstart.auth.
      • Use main class name: com.google.firebase.quickstart.auth.kotlin.MainActivity.
    2. Firebase Console Setup:
      • In the Auth panel > Sign In Method tab, click Facebook.
      • Enable it and click Save.
      • Enter your Facebook App Id and App Secret.
    3. Project Configuration:
      • Open app/src/main/res/values/ids.xml.
      • Replace facebook_app_id and facebook_client_token with the values from your Facebook app.
    4. Run App:
      • Select FacebookLoginFragment from the main screen.
      • Note: Ensure you are running the facebookDebug or facebookRelease build variants to avoid the 'Facebook is disabled' error.