I use IF condition in firebase Notification services class but this condition did not work then i create two diff TOPIC, they also did not work what can i do.....the condition i create it in firebase notification services class is:
public class FirebaseNoficationservices extends FirebaseMessagingService {
private final String CHANNEL_ID="channel_id";
// private final String CHANNEL_IDD="channel_idd";
//String topic;
Intent intent;
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d("remote", remoteMessage.getData().toString());
if((FirebaseMessaging.getInstance().subscribeToTopic("ahmedraza"))!=null){
intent = new Intent(getApplicationContext(), DepartmentHead.class);
}
else if((FirebaseMessaging.getInstance().subscribeToTopic("ahmedraza"))!=null){
intent = new Intent(getApplicationContext(), Admin.class);
}
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int notificationId = new Random().nextInt();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
createNotificationChannel(manager);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("key", remoteMessage.getData().get("name"));
PendingIntent intent1 = PendingIntent.getActivities(this, 0, new Intent[]{intent}, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
Notification notification;
notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle(remoteMessage.getData().get(getString(R.string.name)))
.setContentText(remoteMessage.getData().get(getString(R.string.department)))
.setSmallIcon(R.drawable.rx_notification)
.setAutoCancel(true)
.setContentIntent(intent1)
.build();
manager.notify(notificationId, notification);
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void createNotificationChannel(NotificationManager manager) {
NotificationChannel channel=new NotificationChannel(CHANNEL_ID,"channelName",NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("My description");
channel.enableLights(true);
channel.setLightColor(android.R.color.white);
manager.createNotificationChannel(channel);
}
}
and my main application code are:
if(sendtoDepthead.isChecked()) {
PushNotification notification = new PushNotification(new notificationData(fulnamee.getText().toString(), spinner.getSelectedItem().toString()), TOPIC);
sendNotification(notification);
Toast.makeText(MainActivity.this, "notification sent to manager", Toast.LENGTH_SHORT).show();
}
if(sendtoGeneralmanager.isChecked()){
PushNotification notification = new PushNotification(new notificationData(fulnamee.getText().toString(), spinner.getSelectedItem().toString()), TOPICS);
sendNotification(notification);
Toast.makeText(MainActivity.this, "notification sent to manager", Toast.LENGTH_SHORT).show();
}
and topic subscribe in department head activity is:
FirebaseMessaging.getInstance().subscribeToTopic(TOPIC);
FirebaseMessaging.getInstance().subscribeToTopic(TOPIC)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
String msg = "Subscribed";
if (!task.isSuccessful()) {
msg = "Subscribe failed";
}
Log.d(TAG, msg);
Toast.makeText(DepartmentHead.this, msg, Toast.LENGTH_SHORT).show();
}
});
and the code of notification i send to department head to admin activity is:
PushNotification notification=new PushNotification(new notificationData(nam.getText().toString(),dept.getText().toString()),TOPICS);
sendNotification(notification);
Toast.makeText(DepartmentHead.this,"notification sent to manager",Toast.LENGTH_SHORT).show();
and topic subscribe in my admin activity are:
FirebaseMessaging.getInstance().subscribeToTopic(TOPICS)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
String msg = "Subscribed";
if (!task.isSuccessful()) {
msg = "Subscribe failed";
}
Log.d(TAG, msg);
`Toast.makeText(Admin.this, msg, Toast.LENGTH_SHORT).show();`
}
});
What can i do to get the notification...in application no crashes occur only notification were not send to admin or dept. head classes.
After send the notification i will also send data( using data key) with notification...but i can send notification. can anyone help me to correct the condition of sending to notification for one class to second and second to third.