voice messages for Android 10+

This commit is contained in:
Thomas 2023-07-27 13:57:29 +02:00
parent e06222733c
commit 8c60348939
3 changed files with 17 additions and 8 deletions

View file

@ -304,6 +304,12 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_compose, menu);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
MenuItem micro = menu.findItem(R.id.action_microphone);
if (micro != null) {
micro.setVisible(false);
}
}
return true;
}

View file

@ -1282,9 +1282,9 @@ public class Helper {
MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = mime.getExtensionFromMimeType(cR.getType(uri));
if (uri.toString().endsWith("fedilab_recorded_audio.m4a")) {
extension = ".m4a";
attachment.mimeType = "audio/mp4";
if (uri.toString().endsWith("fedilab_recorded_audio.ogg")) {
extension = "ogg";
attachment.mimeType = "audio/ogg";
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault());
counter++;

View file

@ -274,7 +274,8 @@ public class MediaHelper {
* @param listener ActionRecord
*/
public static void recordAudio(Activity activity, ActionRecord listener) {
String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.m4a";
//String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/fedilab_recorded_audio.ogg";
String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.ogg";
AudioRecorder mAudioRecorder = AudioRecorder.getInstance();
File mAudioFile = new File(filePath);
PopupRecordBinding binding = PopupRecordBinding.inflate(activity.getLayoutInflater());
@ -306,16 +307,18 @@ public class MediaHelper {
binding.counter.setText(String.format(Locale.getDefault(), "%s:%s", minutes, seconds));
});
}
}, 1000, 1000);
}, 0, 1000);
binding.record.setOnClickListener(v -> {
mAudioRecorder.stopRecord();
timer.cancel();
alert.dismiss();
listener.onRecorded(filePath);
});
mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC,
MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.AudioEncoder.AAC,
mAudioFile);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC,
MediaRecorder.OutputFormat.OGG, MediaRecorder.AudioEncoder.OPUS, 48000, 384000,
mAudioFile);
}
mAudioRecorder.startRecord();
}