use proper defaults for notification. fix sound playing twice on Android 8

This commit is contained in:
Daniel Gultsch 2017-08-22 12:19:18 +02:00
parent debbaa8be2
commit 85b502cff9
1 changed files with 12 additions and 12 deletions

View File

@ -4,6 +4,7 @@ import android.app.Notification;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
@ -271,7 +272,7 @@ public class NotificationService {
for(Map.Entry<String,ArrayList<Message>> entry : notifications.entrySet()) { for(Map.Entry<String,ArrayList<Message>> entry : notifications.entrySet()) {
Builder singleBuilder = buildSingleConversations(entry.getValue()); Builder singleBuilder = buildSingleConversations(entry.getValue());
singleBuilder.setGroup(CONVERSATIONS_GROUP); singleBuilder.setGroup(CONVERSATIONS_GROUP);
modifyForSoundVibrationAndLight(singleBuilder,notify,preferences); setNotificationColor(singleBuilder);
notificationManager.notify(entry.getKey(), NOTIFICATION_ID ,singleBuilder.build()); notificationManager.notify(entry.getKey(), NOTIFICATION_ID ,singleBuilder.build());
} }
notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
@ -281,10 +282,11 @@ public class NotificationService {
private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, SharedPreferences preferences) { private void modifyForSoundVibrationAndLight(Builder mBuilder, boolean notify, SharedPreferences preferences) {
final String ringtone = preferences.getString("notification_ringtone", null); final Resources resources = mXmppConnectionService.getResources();
final boolean vibrate = preferences.getBoolean("vibrate_on_notification", true); final String ringtone = preferences.getString("notification_ringtone", resources.getString(R.string.notification_ringtone));
final boolean led = preferences.getBoolean("led", true); final boolean vibrate = preferences.getBoolean("vibrate_on_notification", resources.getBoolean(R.bool.vibrate_on_notification));
final boolean headsup = preferences.getBoolean("notification_headsup", mXmppConnectionService.getResources().getBoolean(R.bool.headsup_notifications)); final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led));
final boolean headsup = preferences.getBoolean("notification_headsup", resources.getBoolean(R.bool.headsup_notifications));
if (notify && !isQuietHours()) { if (notify && !isQuietHours()) {
if (vibrate) { if (vibrate) {
final int dat = 70; final int dat = 70;
@ -293,13 +295,11 @@ public class NotificationService {
} else { } else {
mBuilder.setVibrate(new long[]{0}); mBuilder.setVibrate(new long[]{0});
} }
if (ringtone != null) { Uri uri = Uri.parse(ringtone);
Uri uri = Uri.parse(ringtone); try {
try { mBuilder.setSound(fixRingtoneUri(uri));
mBuilder.setSound(fixRingtoneUri(uri)); } catch (SecurityException e) {
} catch (SecurityException e) { Log.d(Config.LOGTAG,"unable to use custom notification sound "+uri.toString());
Log.d(Config.LOGTAG,"unable to use custom notification sound "+uri.toString());
}
} }
} }
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {