Skip to content

Commit 8a333a9

Browse files
committed
Code clean up for constants and validation for default value for push notification sound.
1 parent 64b34f0 commit 8a333a9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ public final class IterableConstants {
5555
public static final String ICON_FOLDER_IDENTIFIER = "drawable";
5656
public static final String NOTIFICATION_ICON_NAME = "iterable_notification_icon";
5757
public static final String NOTIFICATION_COLOR = "iterable_notification_color";
58+
public static final String DEFAULT_SOUND = "default";
59+
public static final String SOUND_FOLDER_IDENTIFIER = "raw";
60+
public static final String ANDROID_RESOURCE_PATH = "android.resource://";
5861
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotification.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import android.content.pm.PackageManager;
1010
import android.net.Uri;
1111
import android.os.Bundle;
12-
import android.os.Vibrator;
1312
import android.support.v4.app.NotificationCompat;
1413

1514
import java.util.Date;
@@ -71,9 +70,14 @@ public static IterableNotification createNotification(Context context, Bundle ex
7170
String[] soundFile = soundName.split("\\.");
7271
soundName = soundFile[0];
7372

74-
int soundID = context.getResources().getIdentifier(soundName, "raw", context.getPackageName());
75-
Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + soundID);
76-
notificationBuilder.setSound(soundUri);
73+
if (soundName.equalsIgnoreCase(IterableConstants.DEFAULT_SOUND)){
74+
int soundID = context.getResources().getIdentifier(soundName, IterableConstants.SOUND_FOLDER_IDENTIFIER, context.getPackageName());
75+
Uri soundUri = Uri.parse(IterableConstants.ANDROID_RESOURCE_PATH + context.getPackageName() + "/" + soundID);
76+
notificationBuilder.setSound(soundUri);
77+
} else {
78+
notifPermissions.defaults |= Notification.DEFAULT_SOUND;
79+
}
80+
7781
} else {
7882
notifPermissions.defaults |= Notification.DEFAULT_SOUND;
7983
}

0 commit comments

Comments
 (0)