|
|
|
@ -23,10 +23,14 @@ import android.content.BroadcastReceiver;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.media.AudioAttributes;
|
|
|
|
|
import android.media.AudioManager;
|
|
|
|
|
import android.media.MediaPlayer;
|
|
|
|
|
import android.media.Ringtone;
|
|
|
|
|
import android.media.RingtoneManager;
|
|
|
|
|
import android.net.Uri;
|
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
import android.text.Spannable;
|
|
|
|
@ -265,7 +269,6 @@ public class MessageNotifier {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void sendInThreadNotification(Context context, Recipients recipients) {
|
|
|
|
|
try {
|
|
|
|
|
if (!TextSecurePreferences.isInThreadNotifications(context)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -288,29 +291,17 @@ public class MessageNotifier {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MediaPlayer player = new MediaPlayer();
|
|
|
|
|
player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
|
|
|
|
|
player.setDataSource(context, uri);
|
|
|
|
|
player.setLooping(false);
|
|
|
|
|
player.setVolume(0.25f, 0.25f);
|
|
|
|
|
player.prepare();
|
|
|
|
|
|
|
|
|
|
final AudioManager audioManager = ((AudioManager)context.getSystemService(Context.AUDIO_SERVICE));
|
|
|
|
|
|
|
|
|
|
audioManager.requestAudioFocus(null, AudioManager.STREAM_NOTIFICATION,
|
|
|
|
|
AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
|
|
|
|
|
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
|
|
|
|
|
|
|
|
|
|
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onCompletion(MediaPlayer mp) {
|
|
|
|
|
audioManager.abandonAudioFocus(null);
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
|
ringtone.setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
|
|
|
|
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
|
|
|
|
|
.build());
|
|
|
|
|
} else {
|
|
|
|
|
ringtone.setStreamType(AudioManager.STREAM_NOTIFICATION);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
player.start();
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
Log.w("MessageNotifier", ioe);
|
|
|
|
|
}
|
|
|
|
|
ringtone.play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void appendPushNotificationState(@NonNull Context context,
|
|
|
|
|