Allow silent sound

This commit is contained in:
M66B 2019-12-31 09:47:01 +01:00
parent 5ca58988ef
commit 9f1fe2784c
2 changed files with 21 additions and 15 deletions

View File

@ -3149,15 +3149,18 @@ class Core {
Log.i("Notify light enabled");
}
Uri uri = (sound == null ? null : Uri.parse(sound));
if (uri == null || !"content".equals(uri.getScheme()))
uri = null;
Log.i("Notify sound=" + uri);
if (!"".equals(sound)) {
// Not silent sound
Uri uri = (sound == null ? null : Uri.parse(sound));
if (uri != null && !"content".equals(uri.getScheme()))
uri = null;
Log.i("Notify sound=" + uri);
if (uri == null)
def |= DEFAULT_SOUND;
else
builder.setSound(uri);
if (uri == null)
def |= DEFAULT_SOUND;
else
builder.setSound(uri);
}
builder.setDefaults(def);
}

View File

@ -436,7 +436,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
switch (requestCode) {
case ActivitySetup.REQUEST_SOUND:
if (resultCode == RESULT_OK && data != null)
onSelectSound((Uri) data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));
onSelectSound(data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI));
break;
}
} catch (Throwable ex) {
@ -446,13 +446,16 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
private void onSelectSound(Uri uri) {
Log.i("Selected ringtone=" + uri);
if (uri != null && !"content".equals(uri.getScheme()))
uri = null;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
if (uri == null)
prefs.edit().remove("sound").apply();
else
prefs.edit().putString("sound", uri.toString()).apply();
if (uri == null) // silent sound
prefs.edit().putString("sound", "").apply();
else {
if ("content".equals(uri.getScheme()))
prefs.edit().putString("sound", uri.toString()).apply();
else
prefs.edit().remove("sound").apply();
}
}
}