work around for brokens ROMs that expose file uris as notification sound

This commit is contained in:
Daniel Gultsch 2017-05-13 08:10:47 +02:00
parent 5056a28553
commit 2f577097d1
2 changed files with 17 additions and 2 deletions

View File

@ -65,7 +65,7 @@ public class FileBackend {
private static final SimpleDateFormat IMAGE_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); private static final SimpleDateFormat IMAGE_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US);
private static final String FILE_PROVIDER = ".files"; public static final String FILE_PROVIDER = ".files";
private XmppConnectionService mXmppConnectionService; private XmppConnectionService mXmppConnectionService;

View File

@ -22,6 +22,7 @@ import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -40,6 +41,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.ui.ManageAccountActivity; import eu.siacs.conversations.ui.ManageAccountActivity;
import eu.siacs.conversations.ui.SettingsActivity; import eu.siacs.conversations.ui.SettingsActivity;
@ -288,7 +290,12 @@ public class NotificationService {
mBuilder.setVibrate(new long[]{0}); mBuilder.setVibrate(new long[]{0});
} }
if (ringtone != null) { 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) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@ -302,6 +309,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() { private Builder buildMultipleConversation() {
final Builder mBuilder = new NotificationCompat.Builder( final Builder mBuilder = new NotificationCompat.Builder(
mXmppConnectionService); mXmppConnectionService);