Professional Documents
Culture Documents
YOU'RE VIEW ING THE LEGACY DOC S . T HEY ARE DEPRECAT ED AS OF M AY 18, 2 0 16 .
These docs are for version 2.5.2 and below of the Java SDK. Go to our current docs, or see our Android migration
guide.
5 MINUTE QUICKSTART
Ǻňđřǿįđ Qųįčķșțǻřț
Create an account
The first thing you need to do to get started with Firebase is sign up for a free
account. A brand new Firebase app will automatically be created for you with its
own unique URL ending in firebaseio.com. We'll use this URL to store and sync
data.
Install Firebase
To use Firebase features in your Android application you can add a dependency
to Gradle or Maven in your project or download the latest SDK.
As of version 1.1, Firebase has different SDKs for Android and the JVM. This sections
demonstrates Android. If you are developing on the JVM please add a dependency to
firebase-client-jvm instead.
1. dependencies {
2. compile 'com.firebase:firebase-client-android:2.5.2+'
3. }
If you are getting a build error complaining about duplicate files you can
choose to exclude those files by adding the packagingOptions directive
1. android {
2. ...
3. packagingOptions {
4. exclude 'META-INF/LICENSE'
5. exclude 'META-INF/LICENSE-FIREBASE.txt'
6. exclude 'META-INF/NOTICE'
7. }
8. }
If you use Maven to build your application, you can add the following
dependency to your pom.xml:
1. <dependency>
2. <groupId>com.firebase</groupId>
3. <artifactId>firebase-client-android</artifactId>
4. <version>[2.5.2,)</version>
5. </dependency>
https://www.firebase.com/docs/android/quickstart.html 2/7
6/11/2016 Android Quickstart - Firebase
The Firebase library must be initialized once with an Android context. This must
happen before any Firebase app reference is created or used. You can add the
https://www.firebase.com/docs/android/quickstart.html 3/7
6/11/2016 Android Quickstart - Firebase
1. @Override
2. public void onCreate() {
3. super.onCreate();
4. Firebase.setAndroidContext(this);
5. // other setup code
6. }
Writing Data
Once we have a reference to your data, we can write any Boolean,
https://www.firebase.com/docs/android/quickstart.html 4/7
6/11/2016 Android Quickstart - Firebase
Reading Data
Reading data from your Firebase database is accomplished by attaching
an event listener and handling the resulting events. Assuming we
already wrote to myFirebaseRef above, we can retrieve the message
1. myFirebaseRef.child("message").addValueEventListener(new ValueEventListene
2.
3. @Override
4. public void onDataChange(DataSnapshot snapshot) {
5. System.out.println(snapshot.getValue()); //prints "Do you have data?
6. }
7.
8. @Override public void onCancelled(FirebaseError error) { }
9.
10. });
Call getValue() on the DataSnapshot returned from the callback to access the
returned object.
In the example above, the value event will fire once for the initial state of
the data, and then again every time the value of that data changes. You
can learn more about the various event types and how to handle event
data in our documentation on reading data.
https://www.firebase.com/docs/android/quickstart.html 5/7
6/11/2016 Android Quickstart - Firebase
To get started with Email & Password auth, enable the Email & Password
provider in your Firebase app's dashboard:
Now that the authentication provider is enabled you can create a new user:
1. myFirebaseRef.createUser("bobtony@firebase.com", "correcthorsebatterystaple"
2. @Override
3. public void onSuccess(Map<String, Object> result) {
4. System.out.println("Successfully created user account with uid: " +
5. }
6. @Override
7. public void onError(FirebaseError firebaseError) {
8. // there was an error
9. }
10. });
Once you've created your first user, you can log them in using the
authWithPassword method.
Learn how to authenticate via Facebook, Twitter, Google or your own custom
system in our User Authentication guide.
https://www.firebase.com/docs/android/quickstart.html 6/7
6/11/2016 Android Quickstart - Firebase
1. {
2. ".read": true,
3. ".write": "auth.uid === 'admin'",
4. ".validate": "newData.isString() && newData.val().length < 500"
5. }
Firebase enforces your Security and Firebase Rules consistently whenever data
is accessed. The rules language is designed to be both powerful and flexible, so
that you can maintain fine-grained control over your application's data.
What's Next?
Read the Development Guide
https://www.firebase.com/docs/android/quickstart.html 7/7