summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJindong <jindong.yue@nxp.com>2020-07-09 16:43:24 +0800
committerJindong <jindong.yue@nxp.com>2020-07-10 06:59:33 +0800
commitb16e4955942fd761b3288b11d79e1576724f8cae (patch)
tree077e558461c0558af1cbfc2aa0506988d2da3f3c
parent5a698d44461aa8912525f9e1aa7b92804467e6b3 (diff)
downloadSoundRecorder-b16e4955942fd761b3288b11d79e1576724f8cae.tar.gz
change primary directory to /sdcard/Documents
Fix below exception when click record button: E MediaProvider: java.lang.IllegalArgumentException: Primary directory null not allowed for content://media/external_primary/file; allowed directories are [Download, Documents] at com.android.providers.media.MediaProvider.ensureFileColumns(MediaProvider.java:2672) at com.android.providers.media.MediaProvider.ensureUniqueFileColumns(MediaProvider.java:2337) at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:2947) at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3470) at com.android.providers.media.MediaProvider.insert(MediaProvider.java:3198) at com.android.providers.media.MediaProvider.insertFileForFuse(MediaProvider.java:6625) at com.android.providers.media.MediaProvider.insertFileIfNecessaryForFuse(MediaProvider.java:6708) Also removed several extra tabs. Signed-off-by: Jindong <jindong.yue@nxp.com> Change-Id: I8b82a5345d3100763f0426f8d0474d575086100c
-rw-r--r--src/com/android/soundrecorder/Recorder.java15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/com/android/soundrecorder/Recorder.java b/src/com/android/soundrecorder/Recorder.java
index 9d906c2..91b5318 100644
--- a/src/com/android/soundrecorder/Recorder.java
+++ b/src/com/android/soundrecorder/Recorder.java
@@ -137,20 +137,21 @@ public class Recorder implements OnCompletionListener, OnErrorListener {
*/
public void clear() {
stop();
-
+
mSampleLength = 0;
-
+
signalStateChanged(IDLE_STATE);
}
-
+
public void startRecording(int outputfileformat, String extension, Context context) {
stop();
-
+
if (mSampleFile == null) {
- File sampleDir = Environment.getExternalStorageDirectory();
+ File sampleDir = Environment.getExternalStoragePublicDirectory(
+ Environment.DIRECTORY_DOCUMENTS);
if (!sampleDir.canWrite()) // Workaround for broken sdcard support on the device.
sampleDir = new File("/sdcard/sdcard");
-
+
try {
mSampleFile = File.createTempFile(SAMPLE_PREFIX, extension, sampleDir);
} catch (IOException e) {
@@ -158,7 +159,7 @@ public class Recorder implements OnCompletionListener, OnErrorListener {
return;
}
}
-
+
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(outputfileformat);