Updated 14 December 2016
Firebase can power your app’s backend, including data storage, user authentication, static hosting, and more. We provide these services so you can focus on creating extraordinary user experiences.
Firebase Hosting: Deploy our web app in seconds with production-grade static asset hosting. All of our content is delivered over SSL from there global CDN.
1 |
compile 'com.firebase:firebase-client-android:2.3.1' |
NOTE: If you are getting a build error complaining about duplicate files you can choose to exclude those files by adding the packagingOptions
directive to your build.gradle
file:
1 2 3 4 5 6 7 8 |
android { ... packagingOptions { exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE-FIREBASE.txt' exclude 'META-INF/NOTICE' } } |
1 |
<uses-permission android:name="android.permission.INTERNET" /> |
1 2 3 4 5 6 7 8 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Firebase.setAndroidContext(this); Firebase myFirebaseRef = new Firebase("https://glaring-inferno-8411.firebaseio.com/"); ... } |
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
value by using the addValueEventListener
method:
1 2 3 4 5 6 7 |
myFirebaseRef.child("message").addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { System.out.println(snapshot.getValue()); //prints "Do you have data? You'll love Firebase." } @Override public void onCancelled(FirebaseError error) { } }); |
Once we have a reference to your data, we can write any Boolean
, Long
, Double
, Map<String, Object>
or List
object to it using setValue()
:
1 |
myFirebaseRef.child("message").setValue("Do you have data? You'll love Firebase."); |
Stay Updated!!!
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.