Skip to content

Commit af866a9

Browse files
Merge pull request #23 from linhvovan29546/dev/custom-sound
Dev/custom sound
2 parents 304cea4 + d7d404c commit af866a9

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
127127
notificationBody: "Incoming video call",
128128
answerText: "Answer",
129129
declineText: "Decline",
130-
notificationColor:"colorAccent"
130+
notificationColor:"colorAccent",
131+
notificationSound: 'skype_ring'//raw
131132
}
132133
)
133134
```
@@ -145,7 +146,8 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
145146
- `notificationBody`: string (required) body of notification
146147
- `answerText`: string (required) answer button label
147148
- `declineText`: string (required) decline button label
148-
- `notificationColor`: string (optinal) color of notification
149+
- `notificationColor`: string (optional) color of notification
150+
- `notificationSound`: raw file (optional) sound of notification
149151

150152
#### hide notification
151153

@@ -181,6 +183,9 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
181183
RNNotificationCall.backToApp()
182184
```
183185

186+
#### Known issue
187+
- Custom Android notification sound :
188+
- Since Android Oreo / 8 the Notificationsound is coming from the Channel and can only be set the first time you add the channel via your channel.setSound(). If you want to change it later on you need to delete the channel and then re-add it to the system.
184189
## Contributing
185190

186191
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

android/src/main/java/com/reactnativefullscreennotificationincomingcall/FullScreenNotificationIncomingCallModule.java

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void displayNotification(String uuid, @Nullable String avatar,@Nullable i
5555
intent.putExtra("answerText",foregroundOptions.getString("answerText"));
5656
intent.putExtra("declineText",foregroundOptions.getString("declineText"));
5757
intent.putExtra("notificationColor",foregroundOptions.getString("notificationColor"));
58+
intent.putExtra("notificationSound",foregroundOptions.getString("notificationSound"));
5859
intent.setAction(Constants.ACTION_SHOW_INCOMING_CALL);
5960
getReactApplicationContext().startService(intent);
6061
}

android/src/main/java/com/reactnativefullscreennotificationincomingcall/IncomingCallService.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import android.app.NotificationManager;
77
import android.app.PendingIntent;
88
import android.app.Service;
9+
import android.content.ContentResolver;
910
import android.content.Context;
1011
import android.content.Intent;
1112
import android.content.res.Resources;
1213
import android.graphics.Color;
1314
import android.media.AudioAttributes;
1415
import android.media.RingtoneManager;
16+
import android.net.Uri;
1517
import android.os.Build;
1618
import android.os.Bundle;
1719
import android.os.Handler;
@@ -27,6 +29,8 @@
2729
import com.facebook.react.bridge.Arguments;
2830
import com.facebook.react.bridge.WritableMap;
2931

32+
import java.io.File;
33+
3034

3135
public class IncomingCallService extends Service {
3236
private static Runnable handleTimeout;
@@ -99,10 +103,15 @@ private Notification buildNotification(Context context, Intent intent) {
99103
emptyScreenIntent.setAction(Constants.onPressNotification);
100104
String channelId=bundle.getString("channelId");
101105
PendingIntent emptyPendingIntent = PendingIntent.getActivity(context, 0, emptyScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
106+
String customSound=bundle.getString("notificationSound");
107+
Uri sound=RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
108+
if(customSound != null){
109+
sound= Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + File.pathSeparator + File.separator + File.separator + getPackageName() + "/raw/" + customSound);
110+
}
102111
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
103112
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
104113
NotificationChannel notificationChannel=new NotificationChannel(channelId, bundle.getString("channelName"), NotificationManager.IMPORTANCE_HIGH);
105-
notificationChannel.setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE),
114+
notificationChannel.setSound(sound,
106115
new AudioAttributes.Builder()
107116
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
108117
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
@@ -135,7 +144,7 @@ private Notification buildNotification(Context context, Intent intent) {
135144
.setOngoing(true)
136145
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
137146
.setVibrate(new long[] { 0, 1000, 800})
138-
.setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE))
147+
.setSound(sound)
139148
// Use a full-screen intent only for the highest-priority alerts where you
140149
// have an associated activity that you would like to launch after the user
141150
// interacts with the notification. Also, if your app targets Android 10
@@ -213,6 +222,7 @@ private int getResourceIdForResourceName(Context context, String resourceName) {
213222
}
214223
return resourceId;
215224
}
225+
216226
private int getColorForResourceName(Context context, String colorPath){
217227
// java
218228
Resources res = context.getResources();
Binary file not shown.

example/src/App.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ export default function App() {
4444
notificationBody: "Incoming video call",
4545
answerText: "Answer",
4646
declineText: "Decline",
47-
notificationColor: 'colorAccent'//path color in android
47+
notificationColor: 'colorAccent',//path color in android
48+
notificationSound: 'skype_ring'//raw
4849
}
4950
)
5051
// Cancel the timeout if necessary
5152
BackgroundTimer.clearTimeout(timeoutId);
52-
}, 3000);
53+
}, 0);
5354

5455
//rest of code will be performing for iOS on background too
5556

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-full-screen-notification-incoming-call",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Android full screen notification incoming call for React Native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

src/index.tsx

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ enum RNNotificationEvent {
1111
}
1212

1313
interface foregroundOptionsModel {
14-
channelId: string,
15-
channelName: string,
16-
notificationIcon: string,//mipmap
17-
notificationTitle: string,
18-
notificationBody: string,
19-
answerText: string,
20-
declineText: string,
21-
notificationColor?: string
14+
channelId: string;
15+
channelName: string;
16+
notificationIcon: string;//mipmap
17+
notificationTitle: string;
18+
notificationBody: string;
19+
answerText: string;
20+
declineText: string;
21+
notificationColor?: string;
22+
notificationSound?: string//raw
2223
}
2324
class RNNotificationCall {
2425
private _notificationEventHandlers;

0 commit comments

Comments
 (0)