Skip to content

Commit

Permalink
Merge pull request #23 from linhvovan29546/dev/custom-sound
Browse files Browse the repository at this point in the history
Dev/custom sound
  • Loading branch information
linhvovan29546 authored Dec 15, 2022
2 parents 304cea4 + d7d404c commit af866a9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
notificationBody: "Incoming video call",
answerText: "Answer",
declineText: "Decline",
notificationColor:"colorAccent"
notificationColor:"colorAccent",
notificationSound: 'skype_ring'//raw
}
)
```
Expand All @@ -145,7 +146,8 @@ import RNNotificationCall from "react-native-full-screen-notification-incoming-c
- `notificationBody`: string (required) body of notification
- `answerText`: string (required) answer button label
- `declineText`: string (required) decline button label
- `notificationColor`: string (optinal) color of notification
- `notificationColor`: string (optional) color of notification
- `notificationSound`: raw file (optional) sound of notification

#### hide notification

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

#### Known issue
- Custom Android notification sound :
- 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.
## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void displayNotification(String uuid, @Nullable String avatar,@Nullable i
intent.putExtra("answerText",foregroundOptions.getString("answerText"));
intent.putExtra("declineText",foregroundOptions.getString("declineText"));
intent.putExtra("notificationColor",foregroundOptions.getString("notificationColor"));
intent.putExtra("notificationSound",foregroundOptions.getString("notificationSound"));
intent.setAction(Constants.ACTION_SHOW_INCOMING_CALL);
getReactApplicationContext().startService(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -27,6 +29,8 @@
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;

import java.io.File;


public class IncomingCallService extends Service {
private static Runnable handleTimeout;
Expand Down Expand Up @@ -99,10 +103,15 @@ private Notification buildNotification(Context context, Intent intent) {
emptyScreenIntent.setAction(Constants.onPressNotification);
String channelId=bundle.getString("channelId");
PendingIntent emptyPendingIntent = PendingIntent.getActivity(context, 0, emptyScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
String customSound=bundle.getString("notificationSound");
Uri sound=RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
if(customSound != null){
sound= Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + File.pathSeparator + File.separator + File.separator + getPackageName() + "/raw/" + customSound);
}
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel=new NotificationChannel(channelId, bundle.getString("channelName"), NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE),
notificationChannel.setSound(sound,
new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
Expand Down Expand Up @@ -135,7 +144,7 @@ private Notification buildNotification(Context context, Intent intent) {
.setOngoing(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setVibrate(new long[] { 0, 1000, 800})
.setSound(RingtoneManager.getActualDefaultRingtoneUri(getApplicationContext(), RingtoneManager.TYPE_RINGTONE))
.setSound(sound)
// Use a full-screen intent only for the highest-priority alerts where you
// have an associated activity that you would like to launch after the user
// interacts with the notification. Also, if your app targets Android 10
Expand Down Expand Up @@ -213,6 +222,7 @@ private int getResourceIdForResourceName(Context context, String resourceName) {
}
return resourceId;
}

private int getColorForResourceName(Context context, String colorPath){
// java
Resources res = context.getResources();
Expand Down
Binary file not shown.
5 changes: 3 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ export default function App() {
notificationBody: "Incoming video call",
answerText: "Answer",
declineText: "Decline",
notificationColor: 'colorAccent'//path color in android
notificationColor: 'colorAccent',//path color in android
notificationSound: 'skype_ring'//raw
}
)
// Cancel the timeout if necessary
BackgroundTimer.clearTimeout(timeoutId);
}, 3000);
}, 0);

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-full-screen-notification-incoming-call",
"version": "0.1.6",
"version": "0.1.7",
"description": "Android full screen notification incoming call for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
17 changes: 9 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ enum RNNotificationEvent {
}

interface foregroundOptionsModel {
channelId: string,
channelName: string,
notificationIcon: string,//mipmap
notificationTitle: string,
notificationBody: string,
answerText: string,
declineText: string,
notificationColor?: string
channelId: string;
channelName: string;
notificationIcon: string;//mipmap
notificationTitle: string;
notificationBody: string;
answerText: string;
declineText: string;
notificationColor?: string;
notificationSound?: string//raw
}
class RNNotificationCall {
private _notificationEventHandlers;
Expand Down

0 comments on commit af866a9

Please sign in to comment.