Skip to content

Commit

Permalink
Notify user when recording pauses due to another app
Browse files Browse the repository at this point in the history
  • Loading branch information
avazirna committed May 1, 2024
1 parent 7d7ce58 commit 2116cb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/assets/locales/android_translatable_strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ recording.clear=Clear
recording.prompt.with.file.chooser=Record or choose sound below
recording.prompt.without.file.chooser=Record sound below
recording.custom=Recorded Sound
recording.paused.due.another.app.recording.title=CommCare Audio Recording
recording.paused.due.another.app.recording.message=Recording paused as another app with higher privileges started recording. Click here to resume the recording!

callout.failure.dialer=Device is not currently configured to make telephone calls
callout.failure.sms=SMS app not found
Expand Down
1 change: 1 addition & 0 deletions app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,4 +455,5 @@
<string name="fcm_notification">FCM Notification</string>
<string name="fcm_default_notification_channel">notification-channel-push-notifications</string>
<string name="app_with_id_not_found">Required CommCare App is not installed on device</string>
<string name="audio_recording_notification">Audio Recording Notification</string>
</resources>
15 changes: 15 additions & 0 deletions app/src/org/commcare/views/widgets/RecordingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Rect;
Expand Down Expand Up @@ -33,8 +34,11 @@
import androidx.fragment.app.DialogFragment;

import org.commcare.CommCareApplication;
import org.commcare.CommCareNoficationManager;
import org.commcare.activities.DispatchActivity;
import org.commcare.dalvik.R;
import org.commcare.utils.MediaUtil;
import org.commcare.utils.NotificationUtil;
import org.javarosa.core.services.locale.Localization;

import java.io.File;
Expand Down Expand Up @@ -62,6 +66,7 @@ public class RecordingFragment extends DialogFragment {

private static final int HEAAC_SAMPLE_RATE = 44100;
private static final int AMRNB_SAMPLE_RATE = 8000;
private final int RECORDING_NOTIFICATION_ID = R.string.audio_recording_notification;

private String fileName;
private static final String FILE_EXT = ".mp3";
Expand Down Expand Up @@ -433,10 +438,20 @@ public void onRecordingConfigChanged(List<AudioRecordingConfiguration> configs)
if (hasRecordingGoneSilent(configs)) {
if (!inPausedState) {
pauseRecording();
NotificationUtil.showNotification(
getContext(),
CommCareNoficationManager.NOTIFICATION_CHANNEL_USER_SESSION_ID,
RECORDING_NOTIFICATION_ID,
Localization.get("recording.paused.due.another.app.recording.title"),
Localization.get("recording.paused.due.another.app.recording.message"),
new Intent(getContext(), DispatchActivity.class)
.setAction(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER));
}
} else {
if (inPausedState) {
resumeRecording();
NotificationUtil.cancelNotification(getContext(), RECORDING_NOTIFICATION_ID);
}
}
}
Expand Down

0 comments on commit 2116cb0

Please sign in to comment.