Firebase Java
Firebase Java
• What is Firebase?
• History of Firebase
• Why use Firebase?
• General architecture
• Services
• Adding Firebase Realtime Database to Android app
What is Firebase?
https://www.youtube.com/watch?v=vAoB4VbhRzM
• Analytics
Unlimited reporting of 500 event types, each with up to 25
attributes
One dashboard to view user behavior and cross-network
campaign performance
Demographic segmentation, including age, gender, and
location, available out-of-the-box
Export raw data to BigQuery for custom querying
Services (cont.)
• Cloud messaging
Send unlimited upstream/downstream messages
• Authentication
Support multiple social accounts
• Realtime database
A cloud-hosted NoSQL database
Intuitive and easy-to-use API
Remains responsive regardless of network latency or Internet
connectivity
Handles the complexity of real time synchronization and
provides flexible conflict resolution
Accessible directly from client SDKs, or from the server with the
REST API
Services (cont.)
• Storage
Robust uploads and downloads in the background, regardless of
network quality
• Hosting
Automatically provisioned SSL certificate
• Test lab
• Crash reporting
Prioritize crashes by frequency and impact
• Notification
Send free and unlimited notifications across Android and iOS
• Remote config
• App indexing
• Dynamics links
Improve acquisition and engagement by bringing users directly
to content that they were originally searching for, whether they
have your app installed or not
• Invites
• AdWords
Conversion tracking for first opens and in-app events without
implementing any additional SDKs
• AdMOB
Show ads from millions of Google advertisers competing in real
time
Choose a format to suit your app, including banner, video and
native ads
Work with more than 40 top ad networks using AdMob
Mediation
Cross-promote between your apps for free with AdMob house
ads
Adding Firebase Realtime Database to Android app
• Prerequisites
Install or update Android Studio to its latest version (ok, 4.0 is good enough)
Make sure that your project meets these requirements:
- Targets API level 16 (Jelly Bean) or later Oct 3, 2022:
- Uses Gradle 4.1 or later Android Studio Dolphin 2021.3.1
- Uses Jetpack (AndroidX), which includes meeting these version
requirements:
com.android.tools.build:gradle v3.2.1 or later
compileSdkVersion 28 or later
Set up a physical device or use an emulator to run your app
Emulators must use an emulator image with Google Play
Sign into Firebase using your Google account
Adding Firebase Realtime Database to Android app
Step 3. Open the Firebase website and login into it (use the same
email id as used in Android Studio for login)
Step 4. After login, click on the "Go To Console" button that is
present of the upper right side of the website
Adding Firebase Realtime Database to Android app
Step 7. After creating a project, we will see the below image (or
something similar :) of our project dashboard
Adding Firebase Realtime Database to Android app
Step 10. Now, come back to our Android Studio project. We have
to connect our Firebase project with the Android Studio project.
So, click on Tools > Firebase > Realtime Database > Save and
retrieve data OR
“Get started with Realtime Database”
Adding Firebase Realtime Database to Android app
https://firebasetutorials.com/create-firebase-realtime-database/
Adding Firebase Realtime Database to Android app
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textViewID);
FirebaseDatabase.getInstance().getReference().getRoot().child("message1").child("java").
child("user");
dbNode.setValue(null);
//or we can delete the node with the following code too
DatabaseReference dbNodetwo =
FirebaseDatabase.getInstance().getReference().getRoot()
.child("message");
dbNodetwo.removeValue();
}
Adding Firebase Realtime Database to Android app
and be sure that we have the following plugin IDs inside the
build.gradle (Module) file:
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
Adding Firebase Realtime Database to Android app
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textViewID"
android:layout_width="350dp"
android:layout_height="133dp"
android:text="Let us play with Firebase"
android:textSize="26sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.146" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="WriteInfotoFirebase"
android:text="Write info to Firebase"
• activity_main.xml is as follows:
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewID" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="WriteInfotoFirebaseMultiNode"
android:text="Write info: Multi-node"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="DeleteNode"
android:text="Delete node"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button2" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:onClick="UpdateNode"
android:text="Update node"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button3" />
</androidx.constraintlayout.widget.ConstraintLayout>
Adding Firebase Realtime Database to Android app
1. Goto https://console.firebase.google.com/
2. Select your project
3. On the left menu, click on settings > project settings