Top Related Projects
Firebase Android SDK
Optimized UI components for Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Quick Overview
The firebase/quickstart-android repository is a collection of sample Android applications demonstrating various Firebase features and integrations. It provides developers with practical examples and best practices for implementing Firebase services in Android apps, covering areas such as authentication, real-time database, cloud messaging, and more.
Pros
- Comprehensive coverage of Firebase features for Android development
- Well-structured and easy-to-understand code examples
- Regularly updated to reflect the latest Firebase SDK versions and best practices
- Includes both Java and Kotlin implementations for most samples
Cons
- Some samples may not cover advanced use cases or complex scenarios
- Requires basic knowledge of Android development and Firebase concepts
- May not always reflect the most optimized or production-ready implementations
- Limited documentation within the repository itself, relying on external Firebase documentation
Code Examples
- Firebase Authentication (Kotlin):
private fun signIn() {
val signInIntent = googleSignInClient.signInIntent
startActivityForResult(signInIntent, RC_SIGN_IN)
}
private fun firebaseAuthWithGoogle(acct: GoogleSignInAccount) {
val credential = GoogleAuthProvider.getCredential(acct.idToken, null)
auth.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
val user = auth.currentUser
updateUI(user)
} else {
// If sign in fails, display a message to the user
updateUI(null)
}
}
}
- Realtime Database (Kotlin):
private fun writeNewUser(userId: String, name: String, email: String) {
val user = User(name, email)
database.child("users").child(userId).setValue(user)
}
private fun readUserData(userId: String) {
database.child("users").child(userId).addValueEventListener(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
val user = dataSnapshot.getValue(User::class.java)
// Do something with the user data
}
override fun onCancelled(databaseError: DatabaseError) {
// Handle possible errors
}
})
}
- Cloud Messaging (Kotlin):
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
// Handle FCM messages here
if (remoteMessage.notification != null) {
sendNotification(remoteMessage.notification?.body)
}
}
private fun sendNotification(messageBody: String?) {
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)
val channelId = getString(R.string.default_notification_channel_id)
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle(getString(R.string.fcm_message))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0, notificationBuilder.build())
}
}
Getting Started
- Clone the repository:
git clone https://github.com/firebase/quickstart-android.git
- Open the project in Android Studio
- Choose a specific sample app (e.g., auth, database, messaging)
- Follow the README instructions in the chosen sample directory to set up Firebase
- Run the
Competitor Comparisons
Firebase Android SDK
Pros of firebase-android-sdk
- Comprehensive SDK with full Firebase functionality
- Direct access to core Firebase features and APIs
- More flexibility for advanced customization and integration
Cons of firebase-android-sdk
- Steeper learning curve for beginners
- Requires more setup and configuration
- Larger library size, potentially increasing app size
Code Comparison
firebase-android-sdk:
FirebaseApp.initializeApp(this)
val database = FirebaseDatabase.getInstance()
val myRef = database.getReference("message")
myRef.setValue("Hello, Firebase!")
quickstart-android:
// No explicit initialization required
val database = Firebase.database
val myRef = database.getReference("message")
myRef.setValue("Hello, Firebase!")
Summary
firebase-android-sdk is the core SDK providing full access to Firebase features, offering more control and customization options. It's ideal for advanced developers and complex projects. quickstart-android, on the other hand, is designed for beginners and quick prototyping, with simpler setup and usage. It provides a more streamlined experience but may lack some advanced features and flexibility compared to the full SDK. The choice between the two depends on the project's complexity and the developer's familiarity with Firebase.
Optimized UI components for Firebase
Pros of FirebaseUI-Android
- Provides ready-to-use UI components for common Firebase features
- Simplifies authentication flows with pre-built UI elements
- Offers more abstraction, reducing boilerplate code for developers
Cons of FirebaseUI-Android
- Less flexibility for customization compared to quickstart-android
- May include unnecessary dependencies for projects not using all features
- Steeper learning curve for developers new to Firebase
Code Comparison
FirebaseUI-Android:
// Authentication with email
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build()))
.build()
quickstart-android:
// Authentication with email
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
} else {
// If sign in fails, display a message to the user
}
}
FirebaseUI-Android provides a higher-level abstraction for authentication, while quickstart-android offers more granular control over the process. The quickstart-android repository serves as a collection of sample apps demonstrating various Firebase features, whereas FirebaseUI-Android focuses on providing reusable UI components for Firebase integration.
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Pros of react-native-firebase
- Comprehensive React Native support with native Firebase SDKs
- Extensive documentation and community support
- Regular updates and maintenance
Cons of react-native-firebase
- Steeper learning curve for developers new to React Native
- Potential performance overhead due to React Native bridge
Code Comparison
quickstart-android (Java):
FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign up success
} else {
// Sign up failed
}
}
});
react-native-firebase (JavaScript):
import auth from '@react-native-firebase/auth';
auth()
.createUserWithEmailAndPassword(email, password)
.then(() => {
console.log('User account created & signed in!');
})
.catch(error => {
console.error(error);
});
Summary
quickstart-android provides native Android examples for Firebase integration, while react-native-firebase offers a cross-platform solution for React Native developers. The choice between the two depends on the project requirements, target platform, and development team's expertise.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Firebase Quickstarts for Android
A collection of quickstart samples demonstrating the Firebase APIs on Android. For more information, see https://firebase.google.com.
Samples
You can open each of the following samples as an Android Studio project, and run them on a mobile device or a virtual device (AVD). When doing so you need to add each sample app you wish to try to a Firebase project on the Firebase console. You can add multiple sample apps to the same Firebase project. There's no need to create separate projects for each app.
To add a sample app to a Firebase project, use the applicationId
value specified
in the app/build.gradle
file of the app as the Android package name. Download
the generated google-services.json
file, and copy it to the app/
directory of
the sample you wish to run.
- Admob
- Analytics
- App Distribution
- App-Indexing
- Auth
- Config
- Crash
- Database
- Firestore
- Functions
- Dynamic Links
- In-App Messaging
- Messaging
- ML Kit
- ML Kit LanguageID
- ML Kit Smart Reply
- ML Kit Translate
- Performance Monitoring
- Storage
- Vertex AI
How to make contributions?
Please read and follow the steps in the CONTRIBUTING.md
Top Related Projects
Firebase Android SDK
Optimized UI components for Firebase
🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot