Skip to content

Commit 9c16d1c

Browse files
Merge pull request #56 from linhvovan29546/fix/crash-display-notification-avatar-url
fix: app crash when display notification with avatar url
2 parents 70b866a + d88883a commit 9c16d1c

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

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

+9-24
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,22 @@
99
public class CircleTransform implements Transformation{
1010
@Override
1111
public Bitmap transform(Bitmap source) {
12-
int size = Math.min(source.getWidth(), source.getHeight());
13-
14-
int x = (source.getWidth() - size) / 2;
15-
int y = (source.getHeight() - size) / 2;
16-
17-
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
18-
if (squaredBitmap != source) {
19-
source.recycle();
20-
}
21-
22-
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
23-
24-
Canvas canvas = new Canvas(bitmap);
25-
Paint paint = new Paint();
26-
BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
27-
paint.setShader(shader);
28-
paint.setAntiAlias(true);
29-
30-
float r = size/2f;
31-
canvas.drawCircle(r, r, r, paint);
32-
33-
squaredBitmap.recycle();
34-
return bitmap;
12+
return transformWithRecycle(
13+
source,
14+
true
15+
);
3516
}
36-
public static Bitmap transformStatic(Bitmap source) {
17+
18+
public static Bitmap transformWithRecycle(Bitmap source, Boolean isRecycleOriginSource) {
3719
int size = Math.min(source.getWidth(), source.getHeight());
3820

3921
int x = (source.getWidth() - size) / 2;
4022
int y = (source.getHeight() - size) / 2;
4123

4224
Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
25+
if (isRecycleOriginSource && squaredBitmap != source) {
26+
source.recycle();
27+
}
4328
Bitmap bitmap = Bitmap.createBitmap(size, size, source.getConfig());
4429

4530
Canvas canvas = new Canvas(bitmap);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ private void handleNotificationWithAvatar(Bundle bundle, Intent intent) {
119119
}
120120

121121
private void loadAvatarAndStartForeground(String avatarUrl, Intent intent) {
122-
Picasso.get().load(avatarUrl).into(new Target() {
122+
Picasso.get().load(avatarUrl).transform(new CircleTransform()).into(new Target() {
123123
@Override
124124
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
125-
startForegroundWithNotification(intent, CircleTransform.transformStatic(bitmap));
125+
startForegroundWithNotification(intent, CircleTransform.transformWithRecycle(bitmap,false));
126126
}
127127

128128
@Override

example/src/services/CallKeepService.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,23 @@ export class CallKeepService {
106106
if (isAndroid) {
107107
//event only on android
108108
RNCallKeep.addEventListener('showIncomingCallUi', ({ callUUID }) => {
109-
RNNotificationCall.displayNotification(callUUID, null, 30000, {
110-
...answerOption,
111-
channelId: 'com.abc.incomingcall',
112-
channelName: 'Incoming video call',
113-
notificationTitle: 'Linh Vo',
114-
notificationBody: 'Incoming video call',
115-
isVideo: true,
116-
// mainComponent: "MyReactNativeApp",
117-
payload: {
118-
kiokas: 'ádada',
119-
ssskis: 'awq',
120-
},
121-
});
109+
RNNotificationCall.displayNotification(
110+
callUUID,
111+
'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQKet-b99huP_BtZT_HUqvsaSz32lhrcLtIDQ&s',
112+
30000,
113+
{
114+
...answerOption,
115+
channelId: 'com.abc.incomingcall',
116+
channelName: 'Incoming video call',
117+
notificationTitle: 'Linh Vo',
118+
notificationBody: 'Incoming video call',
119+
isVideo: true,
120+
// mainComponent: "MyReactNativeApp",
121+
payload: {
122+
extra: 'extra',
123+
},
124+
}
125+
);
122126
});
123127
// Listen to headless action events
124128
RNNotificationCall.addEventListener(

0 commit comments

Comments
 (0)