I have a messenger application and now I'm doing push notifications part. I'm using FCM (Firebase Cloud Messaging)for this. Now I have a problem. For example introduce 2 users (user1 and user2). If user1 writes me, I'm getting notification with FCM and show it. When user2 writes me, I'm creating new notification for it. But when user1 writes me again and I don't removed my user1 notification, I need to update the notification, else create new. I think you understand me. Now I am stuck at update part, because every time I'm create a new notification on message income.
I searched and found something. It says I have to use NotificationListenerService for this and use getActiveNotifications() for getting all active notifications in status bar.
So I tried something, but I'm getting null. I enabled this application in Notification Access, so I think this is not the problem.
I registered my services in manifest file.
Here is my code, where I created my FCM service. If I done something wrong in my code, please fix it.
public class FireBaseService extends FirebaseMessagingService {
private static final String TAG = "FireBaseMessagingServiceTag";
#SuppressLint("LongLogTag")
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Handle FCM messages here.
Intent service = new Intent(FireBaseService.this, NotificationService.class);
startService(service);
//I think I'm doing wrong here.
NotificationService notificationService = new NotificationService();
StatusBarNotification[] activeNotifications = notificationService.getActiveNotifications();
Log.d(TAG, "Array: " + Arrays.toString(activeNotifications));
//show notification
}
}
And here is the NotificationService class.
public class NotificationService extends NotificationListenerService {
#Override
public IBinder onBind(Intent intent) {
return super.onBind(intent);
}
#Override
public void onListenerConnected() {
super.onListenerConnected();
}
#Override
public void onNotificationPosted(StatusBarNotification sbn){
// Implement what you want here
}
#Override
public void onNotificationRemoved(StatusBarNotification sbn){
// Implement what you want here
}
#Override
public StatusBarNotification[] getActiveNotifications() {
return super.getActiveNotifications();
}
}
So this is all I done. Can you help me? Thank you and please fix my code, if I done something wrong instead of giving bad vote to my question.
Here is the notification part.
private void showNotification(String title, String body) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "com.example.fcmnotification.FireBaseService";
if(notificationManager != null) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(
NOTIFICATION_CHANNEL_ID, "NotificationManager",
NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription("My Channel");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.BLUE);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher_notification)
.setContentTitle(title)
.setContentText(body)
.setContentInfo("info");
notificationManager.notify(new Random().nextInt(), notificationBuilder.build());
}
}
You don't need a NotificationListenerService. Just get the active notifications from the NotificationManager
NotificationManager nm = (NotificationManager)ctx.getSystemService(Activity.NOTIFICATION_SERVICE);
StatusBarNotification[] statusNotifs = null;
try {
statusNotifs = nm.getActiveNotifications();
} catch (Throwable t) {
// it can crash
}
if (statusNotifs != null) for (StatusBarNotification n : statusNotifs) {
Notification notif = n.getNotification();
try {
String ntext = notif.extras.getCharSequence(Notification.EXTRA_TEXT).toString();
// do something
} catch (Throwable t) {
// can crash
}
}
Related
I have implemented the firebase push notification by following a YouTube video and its working fine when app is in the background but when the app goes on the foreground it will not show the notification but I can see the notification coming in the logcat.
here is the code-
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(#NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
getFirebaseMessage(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
}
public void getFirebaseMessage(String title, String msg){
Log.d("abc", title);
Log.d("abc", msg);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "plasmatechannel")
.setSmallIcon(R.drawable.ic_baseline_notifications_active_24)
.setContentTitle(title)
.setContentText(msg)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);
managerCompat.notify(101 , builder.build());
}
}
Starting from API level 26, all notifications must be assigned to a channel to set the behavior that is applied to all notifications in that channel.
Please try to implement the below way in your existing code
NotificationCompat.Builder notificationBuilder = null;
try {
if (Build.VERSION.SDK_INT >= 26) {
try{
NotificationManager notificationManager = (NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.deleteNotificationChannel(Constant.CHANNEL_ID);
NotificationChannel channelnews = new NotificationChannel(Constant.CHANNEL_ID, "Breaking News", NotificationManager.IMPORTANCE_HIGH);
channelnews.enableLights(true);
channelnews.setShowBadge(false);
channelnews.enableVibration(true);
channelnews.setLightColor(Color.WHITE);
channelnews.setVibrationPattern(new long[]{100, 200, 100, 200, 100, 200, 100});
channelnews.setSound(url,new AudioAttributes.Builder().build());
notificationBuilder = new NotificationCompat.Builder(this, Constant.CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher);
notificationManager.createNotificationChannel(channelnews);
}catch (Exception e){
e.printStackTrace();
}
} else {
notificationBuilder = new NotificationCompat.Builder(ctx,"")
.setSmallIcon(R.mipmap.ic_launcher);
}
} catch (Exception e) {
e.printStackTrace();
}
if (notificationBuilder == null) {
notificationBuilder = new NotificationCompat.Builder(ctx,"")
.setSmallIcon(R.mipmap.ic_launcher);
}
notificationBuilder.setContentTitle(title);
notificationBuilder.setContentText(message);
notificationBuilder.setSubText(subtext);
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationNumber, notificationBuilder.build());
Please read detail from
https://developer.android.com/training/notify-user/channels
https://developer.android.com/reference/android/app/NotificationChannel
hope it may help you
That's how the Firebase Push Notification works. It will show notification when your app is in the background. When it is in the foreground, only onMessageReceive is called and you have to perform some action (maybe changing the UI) to notify the user because they are using your app.
I've this receiver the notification displays fine only that only last notification is displayed others are overwritten, How to avoid it?
public class MyBroadCastReceiver extends BroadcastReceiver {
String TAG="onReceiveBroadcasst";
public MyBroadCastReceiver() {
}
Context context;
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
#Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: "+constants.notification);
this.context=context;
notification_maker("Running Late.","Hurry Up, Time to leave.",BitmapFactory.decodeResource(context.getResources(), R.drawable.late));
notification_maker("Forecast.","Today's foreacast",BitmapFactory.decodeResource(context.getResources(), R.drawable.late));
notification_maker("Notification.","Hurry Up, Time to leave.",BitmapFactory.decodeResource(context.getResources(), R.drawable.late));
city=new PrefManager(context).getStringPref("City",city);
}
#RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public void notification_maker(String Title,String notification,Bitmap bitmap) {
Bitmap icon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.cloudy);
NotificationCompat.BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle();
bigPicture.bigPicture(icon1);
ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
toneGenerator.startTone(ToneGenerator.TONE_PROP_BEEP, 1000);
Notification notif = new Notification.Builder(context)
.setContentTitle(Title)
.setContentText(notification)
.setSmallIcon(R.drawable.cloudy)
.setLargeIcon(bitmap)
.setStyle(new Notification.BigTextStyle().bigText(notification)
)
.build();
NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(2,notif);
Log.i(TAG, Title+"notification_maker: "+notification);
}
}
Following code will display only last notification, App-logs have log of other notifications being called successfully, how to avoid it?
The old notifications are being overwritten because you are using the same ID for all of them:
notificationManager.notify(2,notif);
Use different IDs to differentiate the notifications (i.e. don't use 2 to all of your notifications)
i am trying to write a periodic workmanager script but it just run when i open the app and it just run one time (not periodic) !
here is my main activity :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_work);
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,0,intent,0);
NotifyWorker.pendingIntent = pendingIntent;
NotifyWorker.context = this;
PeriodicWorkRequest periodicWorkRequest = new PeriodicWorkRequest.Builder(NotifyWorker.class, 1, TimeUnit.MINUTES).build();
WorkManager.getInstance().enqueue(periodicWorkRequest);
}
}
and this is my dowork method :
public Result doWork() {
Log.i("wd","wd");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,"ctx")
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.logo)
.setContentTitle("Title")
.setContentText("Desc")
.setContentIntent(pendingIntent);
android.app.NotificationManager notificationManager =
(android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
return Result.SUCCESS;
}
why its not run every 1 minute ? what i miss ?
Per the PeriodicWorkRequest.Builder documentation:
The intervalMillis must be greater than or equal to PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS
That value is currently set to 900000 - i.e, 15 minutes.
First of all, you can disagree with my answer but here is the hack which I used in my project and this work very accurately without gives any problem.
It's time to see the code. One thing I pointed later and must read this point after the code. SECTION IMP
//this code in your activity, fragment or any other class
notify_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
OneTimeWorkRequest track_share_market = new OneTimeWorkRequest.Builder(NotificationWorker.class).setInitialDelay(1,TimeUnit.MINUTES).addTag("Stock_Market").build();
WorkManager.getInstance().enqueue(track_share_market);
Log.d("RishabhNotification","SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSs");
}
else {
Log.d("RishabhNotification","FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
WorkManager.getInstance().cancelAllWorkByTag("Stock_Market");
}
}
});
Now your Worker class Code
public class NotificationWorker extends Worker {
public NotificationWorker(#NonNull Context context, #NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
#NonNull
#Override
public Result doWork() {
try {
//Some heavy operation as you want there is no need to make another thread here
//track some website for weather changes or stock market changes
//In my case doWork takes only 10sec for executing this method
ShowNotification("Market Up","Gold Price goes upto ₹25,000 ","Check the app for the new update");
StartNewRequest();
return Result.success();
} catch (Exception e) {
e.printStackTrace();
StartNewRequest();
Log.d("RishabhNotification","ERERERERERERERERERERERERERERERERERERERERERERERERERERERE");
return Result.failure();
}
}
private void StartNewRequest()
{
OneTimeWorkRequest track_market = new OneTimeWorkRequest.Builder(NotificationWorker.class).setInitialDelay(1,TimeUnit.MINUTES).addTag("Stock_Market").build();
WorkManager.getInstance().enqueue(track_market);
}
private void ShowNotification(String Message, String name, String Information)
{
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "Stock Market", NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
notificationChannel.setDescription("Channel description");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
notificationChannel.enableVibration(true);
notificationChannel.setSound(null,null );
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
notificationManager.createNotificationChannel(notificationChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationBuilder.setAutoCancel(false)
.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setSound(uri)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setPriority(Notification.PRIORITY_MAX)
.setContentTitle(Message)
.setContentText(name)
.setContentInfo(Information);
notificationManager.notify(/*notification id*/1, notificationBuilder.build());
}
}
Now Read the SECTION IMP point
This Code perfectly working in Emulator, Pixel phone, Samsung phone, Moto phone, Asus Phone, One plus phone but this same code I tested in the Xioami Devices and Huawei devices they both devices not run the code for every specific time interval(They both run the code but time may be changed) which I define in my code. I don't know why is this happen on both devices. Maybe some optimization. Check this link for more https://www.reddit.com/r/androiddev/comments/9ra0iq/workmanager_reliability_for_periodic_tasks_on/
I have not tested this code in vivo and Oppo devices.
There are lot of questions already available on SO about this topic and I am not saying that I am doing something unique.
In my FirebaseMessagingService, I am sending Broadcast to show Notification when data message is received.
Here is my code:
public class MessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Message data payload: " + remoteMessage.getData());
String topic = remoteMessage.getData().get(AppConstants.Notification.TOPIC);
if(topic != null) {
switch (topic) {
case FirebaseUtils.TopicMessaging.TOPIC_TASK:
String assignedTo = remoteMessage.getData().get(AppConstants.Notification.ASSIGNED_TO);
//String empId = remoteMessage.getData().get(AppConstants.Notification.EMP_ID);
//String assignedBy = remoteMessage.getData().get(AppConstants.Notification.ASSIGNED_BY);
String title = remoteMessage.getData().get(AppConstants.Notification.TITLE);
String body = remoteMessage.getData().get(AppConstants.Notification.BODY);
if (assignedTo.equals(FotApplication.Employee.Id)) {
//sendNotification(body, title);
Intent intent = new Intent("MY_INTENT_FILTER");
intent.putExtra(AppConstants.Notification.ASSIGNED_TO, assignedTo);
intent.putExtra(AppConstants.Notification.TITLE, title);
intent.putExtra(AppConstants.Notification.BODY, body);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
}
break;
}
}
}
In AndroidManifest.xml
<receiver
android:name=".NotificationReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="MY_INTENT_FILTER"/>
</intent-filter>
</receiver>
NotificationReceiver
public class NotificationReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if(intent != null){
String body = null, title = null;
if(intent.hasExtra(AppConstants.Notification.BODY)){
body = intent.getStringExtra(AppConstants.Notification.BODY);
}
if(intent.hasExtra(AppConstants.Notification.TITLE)){
title = intent.getStringExtra(AppConstants.Notification.TITLE);
}
if(body != null && title != null) {
sendNotification(context, body, title);
}
}
}
private void sendNotification(Context context, String message, String title) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
NotificationChannel channel;
if (Build.VERSION.SDK_INT >= 26) {
channel = new NotificationChannel("default",
"Task",
NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription("Task Channel");
notificationManager.createNotificationChannel(channel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "default")
.setSmallIcon(R.drawable.ic_notification_new)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setVibrate(new long[]{0, 500})
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
notificationManager.notify(0, notificationBuilder.build());
}
}
}
NOTE I have tried everything from sending notification from FCM Json to receive it in FirebaseMessagingService but when App is closed (closed mean neither in Foreground nor Background) then notifications did not show up. Though data message is delivered to System tray.
The last thing I am trying to do is sending Broadcast but that's not working as well. Might be my bad. I have gone through several links and implemented every solution but that Notification thing haven't shown up anywhere. Don't know how big giants (WhatsApp, Facebook, Microsoft, Google) are doing it.
How to Send BroadCast from one app to another app
Why is my broadcast receiver not working
Broadcast and Broadcast receiver
FCM Messaging Concept
Firebase cloud messaging notification not received by device
enter link description here
Is there any workaround then let me know!
I am doing lots of Research on push notification but i don't understand how to implement in android 1.6. I want to ask what is the requirements for this? which type of information we get from the server end either in tags form or just information? what will be the input or output regarding this.Which input i give to the server and which output comes from the server.
is there any device id to be require for this? Please suggest me Thanks .
This is the link to documentation given by the Google. They named the concept of PushNotification as C2DM (Cloud To Device Messaging)
You can get a clear description by visiting the given link. I'll give you some short answere for your questions.
You can't implement this in Android 1.6. You need 2.2 or higher
version
As PushNotification, we get only alerts, not the full details message.
As input for the third party server, should have the device registration ID with the C2DM.
Yes, there should be a device id to identify the device to activate the service. You can get it at the initial phase where your Android app try to connect with the C2DM
In Firebase we can push notification with multiple pieces of information to the specific or multiple devices for that we need to implement some code from the android side, first, we need to set up the firebase configuration in your app, I will cover how to redirect push notification to specific or default a screen in the mobile application.
Two ways to open the application screen
By default when you only need to open the application(Like splash screen).
Redirect to the specific screen in the application.
By default when you only need to open the application(Like splash screen)
Create a class Named "FirebaseMessagingService" and extends "FirebaseMessagingService"
Code to implement
public class FirebaseMessagingService extends FirebaseMessagingService
{
#Override
public void onNewToken(String token)
{
sendRegistrationToServer(token);
}
public void onMessageReceived(RemoteMessage remoteMessage)
{
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
Uri imageUrl = remoteMessage.getNotification().getImageUrl();
String actionItem = remoteMessage.getNotification().getClickAction();
if (imageUrl == null)
{
MyNotificationManager.getmInstance(getApplicationContext()).displayNotificationAction(title, body,actionItem);
}
else
{
MyNotificationManager.getmInstance(getApplicationContext()).displayImageNotification(title, body, imageUrl);
}
}
private void sendRegistrationToServer(String token)
{
// TODO: Implement this method to send a token to your app server.
}
}
Create Notification Manager class to manage the display method with different parameters
public class MyNotificationManager
{
private Context mCtx;
private static MyNotificationManager mInstance;
private MyNotificationManager(Context context)
{
createNotificationChannel();
mCtx = context;
}
public static synchronized MyNotificationManager getmInstance(Context context)
{
if (mInstance == null)
{
mInstance = new MyNotificationManager(context);
}
return mInstance;
}
public void createNotificationChannel()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel("1", "Testing the Notification", importance);
channel.setDescription("We are testing the notification");
}
}
public void displayNotification(String title, String body)
{
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx, Constant.CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_notification)
.setColor(ContextCompat.getColor(mCtx, R.color.colorPrimary))
.setContentTitle(title)
.setContentText(body);
Intent intent = new Intent(mCtx, SplashActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pendingIntent);
NotificationManager mNotificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null)
{
mNotificationManager.notify(1, mBuilder.build());
}
}
public void displayImageNotification(String title, String body, Uri imageUrl)
{
NotificationCompat.Builder notification = null;
NotificationManager mNotificationManager = null;
try
{
notification = new NotificationCompat.Builder(mCtx, Constant.CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_notification)
.setContentTitle(title)
.setAutoCancel(true)
.setColor(ContextCompat.getColor(mCtx, R.color.colorPrimary))
.setLargeIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? Picasso.with(mCtx).load(imageUrl).get() : Picasso.with(mCtx).load(R.mipmap.ic_notification).get())
.setContentText(body)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(Picasso.with(mCtx).load(imageUrl).get())
.bigLargeIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? Picasso.with(mCtx).load(imageUrl).get() : Picasso.with(mCtx).load(R.mipmap.ic_notification).get()));
Intent intent = new Intent(mCtx, SplashActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(pendingIntent);
mNotificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null)
{
notification.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(1, notification.build());
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Now just trigger the notification through Firebase console or send through API like:-
{
"to": "device_token",
"priority": "high",
"notification": {
"body": "Happy Coding",
"title": "All things are difficult before they are easy.",
"image":""
},
"data": {
"image":""
}
}
2.Redirect to the specific screen in the application.
Open the AndroidManifest.xml and in activity tag you need to define ...
....
<activity
android:name=".activity.SpedificActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="SpedificActivityNotification" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
....
now call the API
{
"to": "device_token",
"priority": "high",
"notification": {
"body": "Happy Coding",
"title": "All things are difficult before they are easy.",
"click_action": "SpedificActivityNotification",
"image":""
},
"data": {
"image":""
}
}