Reputation: 33
I Have one app in which I am recording sound . App is working fine in <=Api 25 but not in 26 or higher.
Bit of code:
startActivityForResult(new Intent("android.provider.MediaStore.RECORD_SOUND"), REQUEST_CODE_RECORD);
Logcat:
W/System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND }
W/System.err: at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1944)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1618)
at android.app.Activity.startActivityForResult(Activity.java:4501)
at android.app.Activity.startActivityForResult(Activity.java:4459)
at com.clogica.mp3cutter.activity.RingtoneEditActivity.onCreate(RingtoneEditActivity.java:267)
at android.app.Activity.performCreate(Activity.java:7013)
at android.app.Activity.performCreate(Activity.java:7004)
W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2734)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2859)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1592)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6518)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Upvotes: 3
Views: 665
Reputation: 262
You can try this code :
private void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(fileName);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
recorder.start();
}
private void stopRecording() {
recorder.stop();
recorder.release();
recorder = null;
}
for example code https://github.com/manishtheandroider/VoiceRecorderApp
Upvotes: 1
Reputation: 14173
It seems on some devices, there is no application to record sound. You should check whether there is a sound record application or not before starting it.
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CODE_RECORD);
} else {
Toast.makeText(this, "No sound record application found", Toast.LENGTH_SHORT).show();
}
Upvotes: 1
Reputation: 11
You may have to define the permission in the manifest, if not done already.
<uses-permission android:name="android.permission.RECORD_AUDIO" />
However, this issue indicates that there is no default media recorder set up on the device running the later API version.
While you may have a default recorder app on the device, it might not explicitly be defined to map to that specific intent.
You could add your own via a new activity and add recording logic. To specify this you can specify an intent filter similar to:
<activity
android:name="my.audio.RecorderActivity"
android:label="@string/recorder_activity" >
<intent-filter>
<action android:name="android.provider.MediaStore.RECORD_SOUND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Upvotes: 1