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.
6. Create a new project
Create a new project with the com.vogella.android.firebaseexample top level package.
7. 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.
Download the google-services-json file and copy it into the root of your Android app model.
8. 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'
8.1. Configure database access
Select Sign-In Method under authentication and enble Google.
Open the Rules of your database.
9. Firebase links
9.1. vogella Java example code
If you need more assistance we offer Online Training and Onsite training as well as consulting