block call recording in android - android

I want to create application in android which will block call recording.if someone has secretly install call recording app in my phone like virus or something then this app will restrict/prevent all call recording.
so my question is
Is there any way to block call recording?
Thank you in advance.

I think its possible!!! If one android device is running with two different call recording apps, the call will recorded by first app only, which will use the call recording resources in that device, rest of all apps will fail to record, because the resources can be used by one app at a time, its a computation, who will trigger to start using resources will gonna win..it can be your app!!
I'm just giving Idea only, not the perfect solution!!!
Sample code(Not Full code):
MediaRecorder recorder = new MediaRecorder();
Log.d(TAG, "RecordService will config MediaRecorder with audiosource: " + audiosource + " audioformat: " + audioformat);
try {
// These calls will throw exceptions unless you set the
// android.permission.RECORD_AUDIO permission for your app
recorder.reset();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Log.d(TAG, "set encoder default");
recorder.setOutputFile(recording.getAbsolutePath());
Log.d(TAG, "set file: " + recording.getAbsolutePath());
//recorder.setMaxDuration(msDuration); //1000); // 1 seconds
//recorder.setMaxFileSize(bytesMax); //1024*1024); // 1KB
recorder.setOnInfoListener(this);
recorder.setOnErrorListener(this);
try {
recorder.prepare();
} catch (java.io.IOException e) {
Log.e(TAG, "RecordService::onStart() IOException attempting recorder.prepare()\n");
Toast t = Toast.makeText(getApplicationContext(), "CallRecorder was unable to start recording: " + e, Toast.LENGTH_LONG);
t.show();
recorder = null;
return; //return 0; //START_STICKY;
}
Log.d(TAG, "recorder.prepare() returned");
recorder.start();
isRecording = true;
Log.i(TAG, "recorder.start() returned");
//updateNotification(true);
} catch (java.lang.Exception e) {
Toast t = Toast.makeText(getApplicationContext(), "CallRecorder was unable to start recording: " + e, Toast.LENGTH_LONG);
t.show();
Log.e(TAG, "RecordService::onStart caught unexpected exception", e);
recorder = null;
}

Related

Is there a service which provides audio recording within an app?

I'm developing an app that would be utilizing the phone's microphone to record and store audio. However, the quality is horrible.
There are several voice recording apps that use the same mic, but their quality is exceptional.
Are there any services which would allow me to achieve this? I can recall Twilio offering something like this before, but it seems to have stopped. Basically users would be able to record audio clips and then store them for playback later. If a service can do either or both, it would be perfect.
Are you aware of any such service?
You can start MediaRecorder in this way. Here key is setAudioEncodingBitRate and setAudioSamplingRate
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioEncodingBitRate(384000);
recorder.setAudioSamplingRate(48000);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(outputFile); // path of your recording in phone storage
try {
recorder.prepare();
recorder.start();
} catch (IOException e) {
Log.d(TAG, "onCreate: " + e);
}
And you can stop Media recording in this way:
private void stopRecording() {
File file = new File(outputFile); // this is result of recording, you can play this file via MediaPlayer
try {
if (recorder != null) {
recorder.stop();
recorder.release();
recorder = null;
}
} catch (Exception e) {
Log.d(TAG, "stopMediaRecording: ");
} }

Error on some devices starting MediaRecorder start failed -19

I am trying to record video in my app, on my Nexus 5 and a ZTE this code works fine but on Samsumg Galaxy S2 and S3 fails with the exception "start failed -19" I'm a noob with the MediaRecorder, I only need a configuration that works on all cameras that record a .mp4 videofile file with normal quality.
try {
prCamera.unlock();
prMediaRecorder.setCamera(prCamera);
prMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
prMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
prMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoSize(720, 480);
prMediaRecorder.setVideoFrameRate(24);
prMediaRecorder.setVideoEncodingBitRate(3000000);
prMediaRecorder.setAudioEncodingBitRate(12200);
prMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
prMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
prMediaRecorder.setMaxDuration(cMaxRecordDurationInMs);
// Nombre del video de salida
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
nombreVideo = "video_" + timeStamp;
prRecordedFile = new File(cVideoFilePath + nombreVideo + ".mp4");
prMediaRecorder.setOutputFile(prRecordedFile.getPath());
prMediaRecorder.setPreviewDisplay(prSurfaceHolder.getSurface());
try {
prMediaRecorder.prepare();
// Fail on next line
prMediaRecorder.start();
} catch (IllegalStateException e) {
Log.d(tag, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (IOException e) {
Log.d(tag, "IOException preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
} catch (Exception e) {
Log.d(tag, "Unknown exception preparing MediaRecorder: " + e.getMessage());
timer.cancel();
cerrarCamara();
return false;
}
prRecordInProcess = true;
Why you don't use
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
I wasn't able to find the exact settings of this profile but I'm pretty sure the outputformat was mpeg4 and that is what you want...
I remember that most media recorder problems regard to wrong setted parameters. Try use this profile. It guarantees the highest available and working setup for the device. You can read further informations about this and other profiles which may fits your needs better here http://developer.android.com/reference/android/media/CamcorderProfile.html#QUALITY_HIGH

MediaRecorder OnInfoListener giving an 895

I'm using MediaRecorder to allow users to record audio in my app, and for the vast majority of them (and on all my test devices) it is working fine. The relevant code looks like this:
mRecorder = new MediaRecorder();
mRecorder.setOnInfoListener(infoListener);
String audioFilePath = mUri.getPath();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(audioFilePath);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(256 * 1024);
mRecorder.setAudioSamplingRate(44100);
mRecorder.setMaxDuration(60000);
try{
mRecorder.prepare();
}catch (IOException ex){
Log.e(TAG, "Prepare() failed", ex);
mTracker.send(new HitBuilders.ExceptionBuilder()
.setDescription("Preparing MediaRecorder in : " + Thread.currentThread().getName()+ ": " + ex.toString())
.setFatal(false)
.build()
);
}
mRecorder.start();
I have had a report from a user that they are not able to record audio, the toast message that they see is one that I trigger from within the MediaRecorder.onInfoListener.
So I added some Google Analytics and record an event from within that listener to see if I can track down the error:
private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() {
#Override
public void onInfo(MediaRecorder mr, int what, int extra) {
mr.stop();
mr.reset();
mr.release();
mr = null;
onRecordingStopped();
Toast.makeText(mContext, R.string.audio_recording_stopped, Toast.LENGTH_SHORT).show();
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("Error")
.setAction("AudioStopped")
.setLabel("What: " + what + ", extra: " + extra)
.build());
}
};
As you can see I am passing through the 'what' and 'extra' parameters to my Analytics so I can see what kind of errors are occuring.
In my analytics this morning (with just a day of data to go on so far) I am seeing a few with a 'what' of 800 which I can see in the documentation is max duration reached, but the others have a 'what' of 895 which I can find no reference to in the Media.Recorder documentation.
Any suggestions for what 895 means?
I ran into the same problem. Turns out on my device info code 895 meant recording in progress.
That means you don't need to stop the recording.

IllegalStateException when MediaRecorder is recording: how to fix

I got this issue and cant get my head around it, im recording calls directly from the speaker, so when i get TelephonyManager.CALL_STATE_OFFHOOK I instantly start recording audio from VOICE_CALL. thats part its ok, start recording but if the call is ended and start a new one, I get a java.lang.IllegalStateException
I think this is because the first call it's still being recorded... I've tried to do:
mRecorder.stop();
mRecorder.release();
mRecorder.reset();
but no luck, they all gave me a illegalStateException, I just want to know how to stop first call recording and record a new one without errors.
Here's my code for recording and call handling,
//At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
if (state == TelephonyManager.CALL_STATE_OFFHOOK){
if (record_calls == 1){
record_enviroment();
}
}
//when Idle = No activity.
if (state == TelephonyManager.CALL_STATE_IDLE){
//Check for audio recorded and if exists post audio to server
}
public void record_enviroment(){
path = context.getFilesDir().getAbsolutePath() + "/";
try {
//Random number for file name
Random r = new Random( System.currentTimeMillis() );
i = 10000 + r.nextInt(20000);
// Save file local to app
mFileName = path + i + "_call_" + id_asociado + ".3gp";
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e("AUDIO_RECORDER", "prepare() failed");
}
mRecorder.start();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Media Recorder stop() is never called

I am recording an audio file on my broadcast but I am not getting any error but my recorder.stop() is never called heres my code:
String file_name= "recording";
audiofile = File.createTempFile(file_name, ".3gp", sampleDir);
String path=Environment.getExternalStorageDirectory().getAbsolutePath();
//recorder = null;
int audioSource = MediaRecorder.AudioSource.VOICE_CALL;
recorder.setAudioSource(audioSource);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
recorder.prepare();
recorder.start();
and my stop function contains:
public void stopRecord()throws IOException{
if(recorder!=null)
{
recorder.stop();
recorder.release();
recorder.reset();
Log.d(TAG, "recording stopped");
}
else
{
Log.d(TAG, "recording stopped error");
}
i am calling start recorder at offhook stage and stop recorder at idle ,but it goes to idle state and stop is not called at all .
case TelephonyManager.CALL_STATE_IDLE:
prev_state=state;
Log.d(TAG, "CALL_STATE_IDLE==>"+incoming_nr);
Log.d(TAG, "recording stopped"); // Executes till here and skips the below part
try {
stopRecord();
Log.d(TAG, "recording stopped");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(TAG, "recording stopped");
I have give all the permission required pls help me on this
Thanks in Advance
TelephonyManager.EXTRA_STATE_IDLE is called when there is no activity and this is called before TelephonyManager.EXTRA_STATE_OFFHOOK.
Here you are calling stopRecord() function in the TelephonyManager.EXTRA_STATE_IDLE state and thus you are accessing mRecorder.stop();, but at that point Recorder object is null and not initialized. Checdk this post for more clarification Null Exception when recording using mediaRecorder. Also check out the comments.
As far as no error is concerned, you are calling it in try/catch block. So only stack trace will be generated.

Categories

Resources