i am current working on an application. What i want to implement is any time the NotificationModules screen is triggered i want to trigger a sound. here is my code and what i have tried so far. I am using native modules to trigger the sound. Hello guys, i am current working on an application. What i want to implement is any time the NotificationModules screen is triggered i want to trigger a sound. here is my code and what i have tried so far. I am using native modules to trigger the sound. Hello guys, i am current working on an application. What i want to implement is any time the NotificationModules screen is triggered i want to trigger a sound. here is my code and what i have tried so far. I am using native modules to trigger the sound.
package com.limestone.community;
import android.net.Uri;
import com.limestone.community.FullScreenActivity;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.app.PendingIntent;
import android.content.Context;
import android.os.Build;
import androidx.core.app.NotificationCompat;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
public class NotificationModule extends ReactContextBaseJavaModule {
public static ReactApplicationContext reactContext;
NotificationModule(ReactApplicationContext context) {
super(context);
reactContext = context;
}
@Override
public String getName() {
return "NotificationModule";
}
@ReactMethod
public void triggerFullScreenNotification(String title, String message, String channelId) {
NotificationManager notificationManager = (NotificationManager) reactContext
.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
Intent fullScreenIntent = new Intent(reactContext, FullScreenActivity.class);
fullScreenIntent.putExtra("title", title);
fullScreenIntent.putExtra("message", message);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(reactContext, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(reactContext, channelId)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle("Panic Alert")
.setContentText("Immediate attention is required")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setSound(Uri.parse("android.resource://" + reactContext.getPackageName() + "/" + R.raw.custom_sound))
.setFullScreenIntent(fullScreenPendingIntent, true);
notificationManager.notify(1, notificationBuilder.build());
}
};
if (notification.foreground !== true) {
if (notification.data.notificationType === 'Panic') {
if (panicAlert === false) {
dispatch(setTrue());
saveBooleanData('notification', true);
NativeModules.NotificationModule.triggerFullScreenNotification(
notification.data.title,
'A panic alert was raised in your estate',
'limestone',
);
}
}``
}