如何在android中logging电话?
我想做一个应用程序,logging来电和去电。 当用户接听或拨打电话时,它会自动运行。
好的,首先你需要使用设备策略pipe理器,并且需要制作你的设备pipe理设备。 之后,您必须创build一个广播接收器和一个服务。 我在这里发布代码,工作正常。
主要活动:
public class MainActivity extends Activity { private static final int REQUEST_CODE = 0; private DevicePolicyManager mDPM; private ComponentName mAdminName; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try { // Initiate DevicePolicyManager. mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mAdminName = new ComponentName(this, DeviceAdminDemo.class); if (!mDPM.isAdminActive(mAdminName)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Click on Activate button to secure your application."); startActivityForResult(intent, REQUEST_CODE); } else { // mDPM.lockNow(); // Intent intent = new Intent(MainActivity.this, // TrackDeviceService.class); // startService(intent); } } catch (Exception e) { e.printStackTrace(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (REQUEST_CODE == requestCode) { Intent intent = new Intent(MainActivity.this, TService.class); startService(intent); } } }
// DeviceAdminDemo类
public class DeviceAdminDemo extends DeviceAdminReceiver { @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); } public void onEnabled(Context context, Intent intent) { }; public void onDisabled(Context context, Intent intent) { }; }
// TService类
public class TService extends Service { MediaRecorder recorder; File audiofile; String name, phonenumber; String audio_format; public String Audio_Type; int audioSource; Context context; private Handler handler; Timer timer; Boolean offHook = false, ringing = false; Toast toast; Boolean isOffHook = false; private boolean recordstarted = false; private static final String ACTION_IN = "android.intent.action.PHONE_STATE"; private static final String ACTION_OUT = "android.intent.action.NEW_OUTGOING_CALL"; private CallBr br_call; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onDestroy() { Log.d("service", "destroy"); super.onDestroy(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { // final String terminate =(String) // intent.getExtras().get("terminate");// // intent.getStringExtra("terminate"); // Log.d("TAG", "service started"); // // TelephonyManager telephony = (TelephonyManager) // getSystemService(Context.TELEPHONY_SERVICE); // TelephonyManager // // object // CustomPhoneStateListener customPhoneListener = new // CustomPhoneStateListener(); // telephony.listen(customPhoneListener, // PhoneStateListener.LISTEN_CALL_STATE); // context = getApplicationContext(); final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_OUT); filter.addAction(ACTION_IN); this.br_call = new CallBr(); this.registerReceiver(this.br_call, filter); // if(terminate != null) { // stopSelf(); // } return START_NOT_STICKY; } public class CallBr extends BroadcastReceiver { Bundle bundle; String state; String inCall, outCall; public boolean wasRinging = false; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_IN)) { if ((bundle = intent.getExtras()) != null) { state = bundle.getString(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { inCall = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); wasRinging = true; Toast.makeText(context, "IN : " + inCall, Toast.LENGTH_LONG).show(); } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { if (wasRinging == true) { Toast.makeText(context, "ANSWERED", Toast.LENGTH_LONG).show(); String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date()); File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestRecordingDasa1"); if (!sampleDir.exists()) { sampleDir.mkdirs(); } String file_name = "Record"; try { audiofile = File.createTempFile(file_name, ".amr", sampleDir); } catch (IOException e) { e.printStackTrace(); } String path = Environment.getExternalStorageDirectory().getAbsolutePath(); recorder = new MediaRecorder(); // recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(audiofile.getAbsolutePath()); try { recorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } recorder.start(); recordstarted = true; } } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { wasRinging = false; Toast.makeText(context, "REJECT || DISCO", Toast.LENGTH_LONG).show(); if (recordstarted) { recorder.stop(); recordstarted = false; } } } } else if (intent.getAction().equals(ACTION_OUT)) { if ((bundle = intent.getExtras()) != null) { outCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Toast.makeText(context, "OUT : " + outCall, Toast.LENGTH_LONG).show(); } } } } }
清单文件中的权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.STORAGE" />
//my_admin.xml
<device-admin xmlns:android="http://schemas.android.com/apk/res/android" > <uses-policies> <force-lock /> </uses-policies> </device-admin>
//在manifest中声明下面的东西:
声明DeviceAdminDemo类来清单:
<receiver android:name="com.example.voicerecorder1.DeviceAdminDemo" android:description="@string/device_description" android:label="@string/device_admin_label" android:permission="android.permission.BIND_DEVICE_ADMIN" > <meta-data android:name="android.app.device_admin" android:resource="@xml/my_admin" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" /> </intent-filter> </receiver> <service android:name=".TService" > </service>
下面的代码正在为我logging一个即将离任的电话
//Call Recording varibales private static final String AUDIO_RECORDER_FILE_EXT_3GP = ".3gp"; private static final String AUDIO_RECORDER_FILE_EXT_MP4 = ".mp4"; private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder"; private MediaRecorder recorder = null; private int currentFormat = 0; private int output_formats[] = { MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.OutputFormat.THREE_GPP }; private String file_exts[] = { AUDIO_RECORDER_FILE_EXT_MP4, AUDIO_RECORDER_FILE_EXT_3GP }; AudioManager audioManager;
//把这个方法放在oncreate()方法之外
private String getFilename() { String filepath = Environment.getExternalStorageDirectory().getPath(); File file = new File(filepath, AUDIO_RECORDER_FOLDER); if (!file.exists()) { file.mkdirs(); } return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]); } private MediaRecorder.OnErrorListener errorListener = new MediaRecorder.OnErrorListener() { @Override public void onError(MediaRecorder mr, int what, int extra) { Toast.makeText(CallActivity.this, "Error: " + what + ", " + extra, Toast.LENGTH_SHORT).show(); } }; private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { Toast.makeText(CallActivity.this, "Warning: " + what + ", " + extra, Toast.LENGTH_SHORT) .show(); } };
//下面的部分代码,使您的设备在扬声器上
audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.MODE_IN_CALL); audioManager.setSpeakerphoneOn(true);
//下面的部分代码开始录制
recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(output_formats[currentFormat]); //recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(getFilename()); recorder.setOnErrorListener(errorListener); recorder.setOnInfoListener(infoListener); try { recorder.prepare(); recorder.start(); } catch (IllegalStateException e) { Log.e("REDORDING :: ",e.getMessage()); e.printStackTrace(); } catch (IOException e) { Log.e("REDORDING :: ",e.getMessage()); e.printStackTrace(); }
//停止录音,并记住在通话结束或停止时closures扬声器
audioManager.setSpeakerphoneOn(false); try{ if (null != recorder) { recorder.stop(); recorder.reset(); recorder.release(); recorder = null; } }catch(RuntimeException stopException){ }
并授予清单文件的权限,
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
我想对此评论,即使是强硬的老post。 所以,基本上,我想结合2个答案,其中一个来自这篇文章,另一个来自另一篇文章,我不知道它的作者,所以请抱歉使用你的方法。
所以,这里是我的课程达到预期的结果:
public class StartActivity extends Activity { public static final int REQUEST_CODE = 5912; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PackageManager p = getPackageManager(); ComponentName componentName = new ComponentName(this, StartActivity.class); // activity which is first time open in manifiest file which is declare as <category android:name="android.intent.category.LAUNCHER" /> p.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); startService(new Intent(this, StartService.class)); startService(new Intent(this, SmsOutgoingService.class)); try { // Initiate DevicePolicyManager. DevicePolicyManager mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName mAdminName = new ComponentName(this, DeviceAdminReciever.class); if (!mDPM.isAdminActive(mAdminName)) { Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mAdminName); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Click on Activate button to secure your application."); startActivityForResult(intent, REQUEST_CODE); } else { mDPM.lockNow(); finish(); // Intent intent = new Intent(MainActivity.this, // TrackDeviceService.class); // startService(intent); } } catch (Exception e) { e.printStackTrace(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (REQUEST_CODE == requestCode) { startService(new Intent(StartActivity.this, TService.class)); finish(); } super.onActivityResult(requestCode, resultCode, data); } }
而我的TService
类:
public class TService extends Service { private MediaRecorder recorder; private File audiofile; private boolean recordstarted = false; private static final String ACTION_IN = "android.intent.action.PHONE_STATE"; private static final String ACTION_OUT = "android.intent.action.NEW_OUTGOING_CALL"; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public void onDestroy() { Log.d("service", "destroy"); super.onDestroy(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d("StartService", "TService"); final IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_OUT); filter.addAction(ACTION_IN); this.registerReceiver(new CallReceiver(), filter); return super.onStartCommand(intent, flags, startId); } private void startRecording() { File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestRecordingDasa1"); if (!sampleDir.exists()) { sampleDir.mkdirs(); } String file_name = "Record"; try { audiofile = File.createTempFile(file_name, ".amr", sampleDir); } catch (IOException e) { e.printStackTrace(); } String path = Environment.getExternalStorageDirectory().getAbsolutePath(); recorder = new MediaRecorder(); // recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL); recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(audiofile.getAbsolutePath()); try { recorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } recorder.start(); recordstarted = true; } private void stopRecording() { if (recordstarted) { recorder.stop(); recordstarted = false; } } public abstract class PhonecallReceiver extends BroadcastReceiver { //The receiver will be recreated whenever android feels like it. We need a static variable to remember data between instantiations private int lastState = TelephonyManager.CALL_STATE_IDLE; private Date callStartTime; private boolean isIncoming; private String savedNumber; //because the passed incoming is only valid in ringing @Override public void onReceive(Context context, Intent intent) { // startRecording(); //We listen to two intents. The new outgoing call only tells us of an outgoing call. We use it to get the number. if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER"); } else { String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE); String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER); int state = 0; if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) { state = TelephonyManager.CALL_STATE_IDLE; } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { state = TelephonyManager.CALL_STATE_OFFHOOK; } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) { state = TelephonyManager.CALL_STATE_RINGING; } onCallStateChanged(context, state, number); } } //Derived classes should override these to respond to specific events of interest protected abstract void onIncomingCallReceived(Context ctx, String number, Date start); protected abstract void onIncomingCallAnswered(Context ctx, String number, Date start); protected abstract void onIncomingCallEnded(Context ctx, String number, Date start, Date end); protected abstract void onOutgoingCallStarted(Context ctx, String number, Date start); protected abstract void onOutgoingCallEnded(Context ctx, String number, Date start, Date end); protected abstract void onMissedCall(Context ctx, String number, Date start); //Deals with actual events //Incoming call- goes from IDLE to RINGING when it rings, to OFFHOOK when it's answered, to IDLE when its hung up //Outgoing call- goes from IDLE to OFFHOOK when it dials out, to IDLE when hung up public void onCallStateChanged(Context context, int state, String number) { if (lastState == state) { //No change, debounce extras return; } switch (state) { case TelephonyManager.CALL_STATE_RINGING: isIncoming = true; callStartTime = new Date(); savedNumber = number; onIncomingCallReceived(context, number, callStartTime); break; case TelephonyManager.CALL_STATE_OFFHOOK: //Transition of ringing->offhook are pickups of incoming calls. Nothing done on them if (lastState != TelephonyManager.CALL_STATE_RINGING) { isIncoming = false; callStartTime = new Date(); startRecording(); onOutgoingCallStarted(context, savedNumber, callStartTime); } else { isIncoming = true; callStartTime = new Date(); startRecording(); onIncomingCallAnswered(context, savedNumber, callStartTime); } break; case TelephonyManager.CALL_STATE_IDLE: //Went to idle- this is the end of a call. What type depends on previous state(s) if (lastState == TelephonyManager.CALL_STATE_RINGING) { //Ring but no pickup- a miss onMissedCall(context, savedNumber, callStartTime); } else if (isIncoming) { stopRecording(); onIncomingCallEnded(context, savedNumber, callStartTime, new Date()); } else { stopRecording(); onOutgoingCallEnded(context, savedNumber, callStartTime, new Date()); } break; } lastState = state; } } public class CallReceiver extends PhonecallReceiver { @Override protected void onIncomingCallReceived(Context ctx, String number, Date start) { Log.d("onIncomingCallReceived", number + " " + start.toString()); } @Override protected void onIncomingCallAnswered(Context ctx, String number, Date start) { Log.d("onIncomingCallAnswered", number + " " + start.toString()); } @Override protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end) { Log.d("onIncomingCallEnded", number + " " + start.toString() + "\t" + end.toString()); } @Override protected void onOutgoingCallStarted(Context ctx, String number, Date start) { Log.d("onOutgoingCallStarted", number + " " + start.toString()); } @Override protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end) { Log.d("onOutgoingCallEnded", number + " " + start.toString() + "\t" + end.toString()); } @Override protected void onMissedCall(Context ctx, String number, Date start) { Log.d("onMissedCall", number + " " + start.toString()); // PostCallHandler postCallHandler = new PostCallHandler(number, "janskd" , "") } } }
在TService
类中,你会发现CallReceiever
类,它将处理你所需要的一切。 你可以根据你的意愿添加参数,但是,重点是重点。
从您的MainActvitiy电话服务将启动您的收件人。 如果您想要直接从receever录制媒体,您将收到错误,所以您需要从服务中注册Receiever。 之后,你可以打电话开始录音,并结束录音,只要你喜欢。 调用return super.onStartCommand(intent, flags, startId);
将有该服务持续多个电话,所以记住这一点。
最后, AndroidManifest.xml
文件:
<manifest package="your.package.name" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <uses-permission android:name="android.permission.READ_SMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.STORAGE" /> <application android:name=".AppController" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".ui.StartActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <receiver android:name=".io.boot.DeviceAdminReciever" android:permission="android.permission.BIND_DEVICE_ADMIN" > <meta-data android:name="android.app.device_admin" android:resource="@xml/my_admin" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" /> </intent-filter> </receiver> <service android:name=".io.calls.TService" > </service> </application> </manifest>
所以,就是这样,它的function与我的三星Galaxy s6 Edge +完美搭配,Ive在Galaxy Note 4和三星J5上进行了testing,非常感谢这篇文章的作者和关于接收电话的post。
pratt的答案有点不完整,因为当你重新启动你的设备时,你的应用程序将停止工作,录制停止,它变得毫无用处。
即时通讯添加一些复制在您的项目中完成普拉特答案的行。
<receiver android:name=".DeviceAdminDemo" android:permission="android.permission.BIND_DEVICE_ADMIN"> <meta-data android:name="android.app.admin" android:resource="@xml/device_admin" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLED" /> <action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" /> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver>
把这个代码放在DeviceAdminDemo的onReceive中
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); context.stopService(new Intent(context, TService.class)); Intent myIntent = new Intent(context, TService.class); context.startService(myIntent); }
接受的答案是完美的,但不logging去电。 请注意,对于传出的呼叫,这是不可能的(就像我可以告诉从许多职位冲刷),以检测何时实际接听电话(如果有人可以find一个方法,除了淘通知或日志请让我知道)。 最简单的解决方法是在拨出电话时立即开始录音,当检测到IDLE时停止录音。 为了完整性,只需在上面添加与上述相同的类别,
private void startRecord(String seed) { String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date()); File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestRecordingDasa1"); if (!sampleDir.exists()) { sampleDir.mkdirs(); } String file_name = "Record" + seed; try { audiofile = File.createTempFile(file_name, ".amr", sampleDir); } catch (IOException e) { e.printStackTrace(); } String path = Environment.getExternalStorageDirectory().getAbsolutePath(); recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION); recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(audiofile.getAbsolutePath()); try { recorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } recorder.start(); recordstarted = true; } @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_IN)) { if ((bundle = intent.getExtras()) != null) { state = bundle.getString(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { inCall = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); wasRinging = true; Toast.makeText(context, "IN : " + inCall, Toast.LENGTH_LONG).show(); } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { if (wasRinging == true) { Toast.makeText(context, "ANSWERED", Toast.LENGTH_LONG).show(); startRecord("incoming"); } } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { wasRinging = false; Toast.makeText(context, "REJECT || DISCO", Toast.LENGTH_LONG).show(); if (recordstarted) { recorder.stop(); recordstarted = false; } } } } else if (intent.getAction().equals(ACTION_OUT)) { if ((bundle = intent.getExtras()) != null) { outCall = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Toast.makeText(context, "OUT : " + outCall, Toast.LENGTH_LONG).show(); startRecord("outgoing"); if ((bundle = intent.getExtras()) != null) { state = bundle.getString(TelephonyManager.EXTRA_STATE); if (state != null) { if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) { wasRinging = false; Toast.makeText(context, "REJECT || DISCO", Toast.LENGTH_LONG).show(); if (recordstarted) { recorder.stop(); recordstarted = false; } } } } } } }