<?xml version="1.0" encoding="utf-8"?>  <manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.hw.receiver.demo.receiver"      android:versionCode="1"      android:versionName="1.0">      <application android:icon="@drawable/icon" android:label="@string/app_name">          <receiver android:name=".SMSReceive">                          <intent-filter android:priority="800">                  <action android:name="android.provider.Telephony.SMS_RECEIVED" />              </intent-filter>          </receiver>        <receiver android:name=".PhoneReceiver">                          <intent-filter android:priority="800">                  <!-- <action android:name="android.intent.action.NEW_OUTGOING_CALL" />  -->                <action android:name="android.intent.action.PHONE_STATE"/>            </intent-filter>          </receiver>        </application>     <uses-permission android:name="android.permission.READ_PHONE_STATE"/>      <uses-permission android:name="android.permission.RECEIVE_SMS"/>      <uses-permission android:name="android.permission.RECORD_AUDIO"/>  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  </manifest>  


import java.io.File;import java.io.IOException;import java.util.Set;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.media.MediaRecorder;import android.os.Bundle;import android.telephony.TelephonyManager;import android.util.Log;import android.widget.Toast;public class PhoneReceiver extends BroadcastReceiver  {private static final String TAG = "PhoneReceiver";private static MediaRecorder recorder;private static boolean callOver = false;@Overridepublic void onReceive(Context context, Intent intent) {if(intent.getAction().equals("android.intent.action.PHONE_STATE")){String phoneState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);/*StringBuffer sb = new StringBuffer();String incomingNumber = intent.getStringExtra("incoming_number");String outgoingNumber = intent.getStringExtra("outgoing_number");     Bundle bundle = intent.getExtras();Set<String> set = bundle.keySet();for(String key:set){sb.append(key).append(":").append(bundle.get(key)).append("\n");}sb.append(intent.getAction()).append("\n");sb.append("IncomingNumber:").append(incomingNumber).append("\n");sb.append("OutGoingNumber:").append(outgoingNumber).append("\n");sb.append("PhoneState:").append(phoneState).append("\n");Toast.makeText(context, sb.toString()                  , 5000).show();Log.d(TAG, sb.toString());*/if(phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)){if(callOver){stopRecord();callOver = false;}Log.d(TAG, "IDLE");}else if(phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){callOver = true;startRecord();Log.d(TAG, "OFFHOOK");}else if(phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)){Log.d(TAG, "RINGING");}}}    private void startRecord(){    Log.d(TAG, "startRecord");    String path = "/sdcard/test.mp3";    recorder = new MediaRecorder();    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);    Log.d(TAG, path);    recorder.setOutputFile(path);    try {recorder.prepare();} catch (IllegalStateException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}     recorder.start();    }    private void stopRecord(){    Log.d(TAG, "stopRecord");    Log.d(TAG, ""+recorder);    recorder.stop();    recorder.release();    recorder = null;    }}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 基于mysql中delete的语法别名问题
  2. MySQL 用 limit 为什么会影响性能
  3. 一次MySQL启动导致的事故实战记录
  4. MySQL中几种插入和批量语句实例详解
  5. MySQL 如何限制一张表的记录数
  6. MySQL into_Mysql中replace与replace int
  7. MYSQL 的10大经典优化案例场景实战
  8. MySQL 数据库定时备份的几种方式(全面)
  9. Mysql 字符集不一致导致连表异常的解决
  10. 五分钟带你搞懂MySQL索引下推