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