aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-05-17 22:03:14 +0200
committerChristian Schneppe <christian@pix-art.de>2017-05-17 22:03:14 +0200
commita82d52a8544a7dd55a8ee69df2134ca75c43624d (patch)
tree063fbac965c1e60e4112dd42c60894f6eb11e4c2 /src/main
parentcf613ce4a0b1f5b37bb2c33d16e961e02fb9b526 (diff)
work around for brokens ROMs that expose file uris as notification sound
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java2
-rw-r--r--src/main/java/de/pixart/messenger/services/NotificationService.java17
2 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index 01a4070f1..8f8d3bc70 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -65,7 +65,7 @@ public class FileBackend {
private static final SimpleDateFormat fileDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmssSSS", Locale.US);
- private static final String FILE_PROVIDER = ".files";
+ public static final String FILE_PROVIDER = ".files";
private XmppConnectionService mXmppConnectionService;
diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java
index e351bbb89..917bc9c30 100644
--- a/src/main/java/de/pixart/messenger/services/NotificationService.java
+++ b/src/main/java/de/pixart/messenger/services/NotificationService.java
@@ -22,6 +22,7 @@ import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Pair;
+import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Calendar;
@@ -40,6 +41,7 @@ import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
+import de.pixart.messenger.persistance.FileBackend;
import de.pixart.messenger.ui.ConversationActivity;
import de.pixart.messenger.ui.EditAccountActivity;
import de.pixart.messenger.ui.ManageAccountActivity;
@@ -300,7 +302,12 @@ public class NotificationService {
mBuilder.setVibrate(new long[]{0});
}
if (ringtone != null) {
- mBuilder.setSound(Uri.parse(ringtone));
+ Uri uri = Uri.parse(ringtone);
+ try {
+ mBuilder.setSound(fixRingtoneUri(uri));
+ } catch (SecurityException e) {
+ Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString());
+ }
}
}
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -314,6 +321,14 @@ public class NotificationService {
}
}
+ private Uri fixRingtoneUri(Uri uri) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(uri.getScheme())) {
+ return FileBackend.getUriForFile(mXmppConnectionService, new File(uri.getPath()));
+ } else {
+ return uri;
+ }
+ }
+
private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder(
mXmppConnectionService);