work around for brokens ROMs that expose file uris as notification sound
This commit is contained in:
parent
5056a28553
commit
2f577097d1
|
@ -65,7 +65,7 @@ public class FileBackend {
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 eu.siacs.conversations.entities.Account;
|
|||
import eu.siacs.conversations.entities.Contact;
|
||||
import eu.siacs.conversations.entities.Conversation;
|
||||
import eu.siacs.conversations.entities.Message;
|
||||
import eu.siacs.conversations.persistance.FileBackend;
|
||||
import eu.siacs.conversations.ui.ConversationActivity;
|
||||
import eu.siacs.conversations.ui.ManageAccountActivity;
|
||||
import eu.siacs.conversations.ui.SettingsActivity;
|
||||
|
@ -288,7 +290,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) {
|
||||
|
@ -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() {
|
||||
final Builder mBuilder = new NotificationCompat.Builder(
|
||||
mXmppConnectionService);
|
||||
|
|
Loading…
Reference in a new issue