I have created few channels for different notifications in my MainActivity.java in one of the channel i want to activate reply from notification feature
For Custom reply button using Notification Compat to build the notification but it is not working
here is my code in Main activity
public class Main Activity extends React Activity {
private static final String CHANNEL_ID_REMARKS = "remarks channel";
private static final String CHANNEL_ID_ALARM = "alarm_channel";
public static final String REPLY_ACTION = "com.appname.REPLY_ACTION";
public static final String KEY_TEXT_REPLY = "key_text_reply";
@Override
protected void onCreate(Bundle savedInstanceState) {
createNotificationChannels();
super.onCreate((savedInstanceState));
}
private void createNotificationChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel tokyoChannel = new NotificationChannel("tokyo_channel", "{appname}}", NotificationManager.IMPORTANCE_HIGH);
tokyoChannel.setShowBadge(true);
tokyoChannel.setDescription("");
AudioAttributes atttokyo = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
tokyoChannel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/tokyo"), atttokyo);
tokyoChannel.enableVibration(true);
tokyoChannel.setVibrationPattern(new long[]{400, 400});
tokyoChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationChannel remarksChannel = new NotificationChannel("remarks_Channel", "{appname}}", NotificationManager.IMPORTANCE_HIGH);
remarksChannel.setShowBadge(true);
remarksChannel.setDescription("");
AudioAttributes attremarks = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
remarksChannel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/alarm"), attremarks);
remarksChannel.enableVibration(true);
remarksChannel.setVibrationPattern(new long[]{400, 400});
remarksChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationChannel alarmChannel = new NotificationChannel("alarm_channel", "{appname}}", NotificationManager.IMPORTANCE_HIGH);
alarmChannel.setShowBadge(true);
alarmChannel.setDescription("");
AudioAttributes attalarm = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build();
alarmChannel.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/alarm"), attalarm);
alarmChannel.enableVibration(true);
alarmChannel.setVibrationPattern(new long[]{400, 400});
alarmChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(tokyoChannel);
manager.createNotificationChannel(remarksChannel);
manager.createNotificationChannel(alarmChannel);
}
}```
here it is for reply reciver
public class ReplyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (MyFirebaseMessagingService.REPLY_ACTION.equals(intent.getAction())) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
String replyText = remoteInput.getCharSequence(MyFirebaseMessagingService.KEY_TEXT_REPLY).toString();
Toast.makeText(context, "Reply: " + replyText, Toast.LENGTH_SHORT).show();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(1); =
}
}
}
}```