|
6 | 6 | import android.app.NotificationManager;
|
7 | 7 | import android.app.PendingIntent;
|
8 | 8 | import android.app.Service;
|
| 9 | +import android.content.ContentResolver; |
9 | 10 | import android.content.Context;
|
10 | 11 | import android.content.Intent;
|
11 | 12 | import android.content.res.Resources;
|
12 | 13 | import android.graphics.Color;
|
13 | 14 | import android.media.AudioAttributes;
|
14 | 15 | import android.media.RingtoneManager;
|
| 16 | +import android.net.Uri; |
15 | 17 | import android.os.Build;
|
16 | 18 | import android.os.Bundle;
|
17 | 19 | import android.os.Handler;
|
|
27 | 29 | import com.facebook.react.bridge.Arguments;
|
28 | 30 | import com.facebook.react.bridge.WritableMap;
|
29 | 31 |
|
| 32 | +import java.io.File; |
| 33 | + |
30 | 34 |
|
31 | 35 | public class IncomingCallService extends Service {
|
32 | 36 | private static Runnable handleTimeout;
|
@@ -99,10 +103,15 @@ private Notification buildNotification(Context context, Intent intent) {
|
99 | 103 | emptyScreenIntent.setAction(Constants.onPressNotification);
|
100 | 104 | String channelId=bundle.getString("channelId");
|
101 | 105 | 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 | + } |
102 | 111 | NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
103 | 112 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
104 | 113 | NotificationChannel notificationChannel=new NotificationChannel(channelId, bundle.getString("channelName"), NotificationManager.IMPORTANCE_HIGH);
|
105 |
| - notificationChannel.setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE), |
| 114 | + notificationChannel.setSound(sound, |
106 | 115 | new AudioAttributes.Builder()
|
107 | 116 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
108 | 117 | .setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
@@ -135,7 +144,7 @@ private Notification buildNotification(Context context, Intent intent) {
|
135 | 144 | .setOngoing(true)
|
136 | 145 | .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
137 | 146 | .setVibrate(new long[] { 0, 1000, 800})
|
138 |
| - .setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE)) |
| 147 | + .setSound(sound) |
139 | 148 | // Use a full-screen intent only for the highest-priority alerts where you
|
140 | 149 | // have an associated activity that you would like to launch after the user
|
141 | 150 | // interacts with the notification. Also, if your app targets Android 10
|
@@ -213,6 +222,7 @@ private int getResourceIdForResourceName(Context context, String resourceName) {
|
213 | 222 | }
|
214 | 223 | return resourceId;
|
215 | 224 | }
|
| 225 | + |
216 | 226 | private int getColorForResourceName(Context context, String colorPath){
|
217 | 227 | // java
|
218 | 228 | Resources res = context.getResources();
|
|
0 commit comments