better check soundid passed to AlarmSoundService
This commit is contained in:
parent
b572d110d8
commit
628adf25ba
|
@ -97,12 +97,14 @@ public class ErrorDialog extends DialogFragment implements View.OnClickListener
|
|||
}
|
||||
|
||||
private void startAlarm() {
|
||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||
alarm.putExtra("soundid", soundId);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
MainApp.instance().startForegroundService(alarm);
|
||||
else
|
||||
MainApp.instance().startService(alarm);
|
||||
if (soundId != 0) {
|
||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||
alarm.putExtra("soundid", soundId);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
MainApp.instance().startForegroundService(alarm);
|
||||
else
|
||||
MainApp.instance().startService(alarm);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopAlarm() {
|
||||
|
|
|
@ -18,7 +18,7 @@ public class ErrorHelperActivity extends AppCompatActivity {
|
|||
ErrorDialog errorDialog = new ErrorDialog();
|
||||
errorDialog.setHelperActivity(this);
|
||||
errorDialog.setStatus(getIntent().getStringExtra("status"));
|
||||
errorDialog.setSound(getIntent().getIntExtra("soundid", 0));
|
||||
errorDialog.setSound(getIntent().getIntExtra("soundid", R.raw.error));
|
||||
errorDialog.setTitle(getIntent().getStringExtra("title"));
|
||||
errorDialog.show(this.getSupportFragmentManager(), "Error");
|
||||
|
||||
|
|
|
@ -7,13 +7,14 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -66,7 +67,7 @@ public class NotificationStore {
|
|||
|
||||
if (SP.getBoolean(MainApp.gs(R.string.key_raise_notifications_as_android_notifications), false) && !(n instanceof NotificationWithAction)) {
|
||||
raiseSystemNotification(n);
|
||||
if (usesChannels && n.soundId != null) {
|
||||
if (usesChannels && n.soundId != null && n.soundId != 0) {
|
||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||
alarm.putExtra("soundid", n.soundId);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
|
@ -76,7 +77,7 @@ public class NotificationStore {
|
|||
}
|
||||
|
||||
} else {
|
||||
if (n.soundId != null) {
|
||||
if (n.soundId != null && n.soundId != 0) {
|
||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||
alarm.putExtra("soundid", n.soundId);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
|
@ -146,7 +147,7 @@ public class NotificationStore {
|
|||
if (n.level == Notification.URGENT) {
|
||||
notificationBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000})
|
||||
.setContentTitle(MainApp.gs(R.string.urgent_alarm))
|
||||
.setSound(sound, AudioAttributes.USAGE_ALARM);
|
||||
.setSound(sound, AudioManager.STREAM_ALARM);
|
||||
} else {
|
||||
notificationBuilder.setVibrate(new long[]{0, 100, 50, 100, 50})
|
||||
.setContentTitle(MainApp.gs(R.string.info))
|
||||
|
|
|
@ -1529,6 +1529,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
||||
} else {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", MainApp.gs(R.string.medtronic_error_operation_not_possible_no_configuration));
|
||||
i.putExtra("title", MainApp.gs(R.string.combo_warning));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
|
|
@ -51,28 +51,22 @@ public class AlarmSoundService extends Service {
|
|||
resourceId = intent.getIntExtra("soundid", R.raw.error);
|
||||
|
||||
player = new MediaPlayer();
|
||||
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);
|
||||
if (afd == null)
|
||||
return START_STICKY;
|
||||
try {
|
||||
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);
|
||||
if (afd == null)
|
||||
return START_STICKY;
|
||||
player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
|
||||
afd.close();
|
||||
} catch (IOException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
player.setLooping(true); // Set looping
|
||||
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (manager == null || !manager.isMusicActive()) {
|
||||
player.setVolume(100, 100);
|
||||
}
|
||||
|
||||
try {
|
||||
player.setLooping(true); // Set looping
|
||||
AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
|
||||
if (manager == null || !manager.isMusicActive()) {
|
||||
player.setVolume(100, 100);
|
||||
}
|
||||
player.prepare();
|
||||
player.start();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue