Hello, I have a question while using the Firebase push message function.
I'm currently creating a community app
By the way, each push message has a different content, but all the contents are transferred to LoginActivity.
By any chance,
I tried to override the method, but I can't execute the overridden method... The execution code is as follows:
Thank you.
private void sendNotification(String title, String text) {
// Create channel - from skd 26?
// // todo
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// If you press a push message, go to the login activity.
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_share_black_24dp)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[]{100, 200, 100, 200})
.setPriority(Notification.PRIORITY_HIGH)
// Apply Channel
.setChannelId(ChannerId)
.setContentIntent(pendingIntent);
// Apply Channel
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel notificationChannel
= = new NotificationChannel(ChannerId, "ChattingApp", NotificationManager.IMPORTANCE_DEFAULT);
notificationChannel.setDescription ("Service Strategic Management Association (SSMA).");
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.GREEN);
notificationChannel.enableVibration(true);
notificationChannel.setVibrationPattern(new long[]{100, 200, 100, 200});
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(notificationChannel);
}
if (notificationManager != null) {
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
// Create Channel - < 26
else {
// If you press a push message, proceed to the login activity.
// // todo
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_share_black_24dp)
.setContentTitle(title)
.setContentText(text)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[]{100, 200, 100, 200})
.setPriority(Notification.PRIORITY_HIGH)
// Apply Channel
// // .setChannelId(ChannerId)
.setContentIntent(pendingIntent);
// Apply Channel
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
I solved it. It would be helpful if there are people who have the same difficulties.
You can hand over the values in the method that sends the push message, and modify the onMessageReceived() code.
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
String title = remoteMessage.getData().get("title");
String text = remoteMessage.getData().get("text");
String caseNumber = remoteMessage.getData().get("caseNumber");
String index = remoteMessage.getData().get("index");
// Drop it to 1:1 chat room.
if (caseNumber.equals("0")) {
sendNotification0(title, text, index);
}
// 1: Drop them into the chat room.
if (caseNumber.equals("1")) {
sendNotification1(title, text, index);
}
// Drop it to the bulletin board.
if (caseNumber.equals("2")) {
sendNotification2(title, text);
}
}
}
582 PHP ssh2_scp_send fails to send files as intended
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.