Prerequisite to Create Push Notification for Android App

The following article will give you the understanding to implement Push Notification for your Android App.

1. Push notification implementation in the android app: 
Create a Firebase project 
Before you can add Firebase to your Android app, you need to create a Firebase project to connect to your Android app. Visit Understand Firebase Projects to learn more about Firebase projects.
a. Create a Firebase project:- b. Register your app with Firebase To use Firebase in your Android app, you need to register your app with your Firebase project. Registering your app is often called "adding" your app to your project.
Note: Check out our best practices for adding apps to a Firebase project, including how to handle multiple variants.
1. Go to the Firebase console
2. In the center of the project overview page, click the Android icon (plat_android) or Add app to launch the setup workflow. 
3. Enter your app's package name in the Android package name field. 
What's a package name, and where do you find it? 
Make sure to enter the package name that your app is actually using. The package name value is case-sensitive, and it cannot be changed for this Firebase Android app after it's registered with your Firebase project. 
4. (Optional) Enter other app information: App nickname and Debug signing certificate SHA-1
How are the App nickname and the Debug signing certificate SHA-1 used within Firebase? 
5. Click the Register app
C. Add a Firebase configuration file 
1. Download and then add the Firebase Android configuration file (google-services.json) to your app: a. Click Download google-services.json to obtain your Firebase Android config file. b. Move your config file into the module (app-level) root directory of your app.
What do you need to know about this config file? 
2. To make the values in your google-services.json config file accessible to Firebase SDKs, you need the Google services Gradle plugin (google-services). 
a. In your root-level (project-level) Gradle file (<project>/build.gradle), add the Google services plugin as a buildscript dependency: 
buildscript { 
repositories { 
google() 
mavenCentral() 
dependencies { 
// Add the dependency for the Google services Gradle plugin classpath 'com.google.gms:google-services:4.3.14'
 } 
allprojects { 
repositories { 
google() 
mavenCentral() } 
}
In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle), add the Google services plugin: 
plugins { 
id 'com.android.application' 
// Add the Google services Gradle plugin
id 'com.google.gms.google-services' 
... 
d. Add Firebase SDKs to your app 
In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle), add the dependency for the Firebase Cloud Messaging Android library. We recommend using the Firebase Android BoM to control library versioning. 
For an optimal experience with Firebase Cloud Messaging, we recommend enabling Google Analytics in your Firebase project and adding the Firebase SDK for Google Analytics to your app.
dependencies {
implementation 'com.google.firebase:firebase-core:21.1.1' 
implementation 'com.google.firebase:firebase-messaging:23.1.1' 
implementation 'com.google.firebase:firebase-auth:21.1.0' 
}
e. Add androidmenifest.xml in the code
<service 
android:name=".fcm.FireBaseMessagingService"
android:enable="true" 
android:exported="false"> 
<intent-filter> 
<action android:name="com.google.firebase.MESSAGING_EVENT" /> 
</intent-filter> </service>
<meta-data 
android:name="com.google.firebase.messaging.default_notification_icon" 
android:resource="@drawable/abc_vector_test" /> 
<meta-data 
android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/blue" />
f. Retrieve the current registration token 

This code is implemented in Home Activity
FirebaseMessaging.getInstance().getToken() 
.addOnCompleteListener(new OnCompleteListener<String>() { 
@Override 
public void onComplete(@NonNull Task<String> task) { 
if (!task.isSuccessful()) { 
Log.w(TAG, "Fetching FCM registration token failed", task.getException()); return; } String token = task.getResult(); // Log and toast String msg = getString(R.string.msg_token_fmt, token); Log.d(TAG, msg); Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); 
});
2. Nudge api in app
File name = LoginViewModel
Nudge api after login successfully in the app
Internal fun callNotificationApi(){
}
This function is call for nudge api in your app

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.