Home Tutorials Training Consulting Products Books Company Donate Contact us









NOW Hiring

Quick links

Share

Using the Firebase database for storing data in Android.

1. Firebase database

Firebase is a real time data base which allows to store tree of lists of objects. It allows to synchronize data between different devices. It is a NoSQL JSON database.

You can find it under: https://console.firebase.google.com/

2. Configure firebase

Logon to https://console.firebase.google.com/ and press Add Firebase to your Android app.

3. Integrating into your application

Add the following gradle dependencies to your general gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // more stuff
    dependencies {
        // classpath com.android.tools.build:gradle entry as before
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

 // more stuff

Add the following gradle dependencies to your app gradle file

dependencies {
  // ... more stuff
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}

apply plugin: 'com.google.gms.google-services'

4. Access

Access to your Firebase Database is configured by a set of rules written in a JSON configuration language. == Exercise: Building an Android application using the firebase database

5. Create a new project

Create a new project with the com.vogella.android.firebaseexample top level package.

6. Configure firebase

Logon to https://console.firebase.google.com/ Create a new project and call it vogellachat.

In your new project, select Add Firebase to your Android app.

For this you need to get the SHA-1 for your debug keystore:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v -storepass android

Enter the package and your SHA-1 into the webmask and press Register app.

Firebase registration

Download the google-services-json file and copy it into the root of your Android app model.

Firebase registration

7. Integrating into your application

Add the following gradle dependencies to your general gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    // more stuff
    dependencies {
        // classpath com.android.tools.build:gradle entry as before
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

 // more stuff

Add the following gradle dependencies to your app gradle file

dependencies {
  // ... more stuff
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-auth:10.2.1'
}

apply plugin: 'com.google.gms.google-services'

7.1. Configure database access

Select Sign-In Method under authentication and enble Google.

Sign-in methods
Sign-in methods

Open the Rules of your database.

Access rules for the database

8. About this website

9.1. vogella GmbH training and consulting support

TRAINING SERVICE & SUPPORT

The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.

The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.

Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.

See Licence.