android 通话录音

本文介绍了如何在Android中实现通话录音,包括注册通话状态广播接收器、处理通话录音的代码逻辑,以及启动和停止录音服务的方法。通过监听电话状态,使用MediaRecorder进行录音,并在通话结束后保存录音文件。
摘要由CSDN通过智能技术生成

一:通话录音状态广播注册

  <receiver android:name="com.example.receiver.PhoneReceiver" >
            <intent-filter android:priority="1000" >
                <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
                <action android:name="android.intent.action.ACTION_NEW_OUTGOING_CALL" />
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>

 

二:通话录音代码

public class PhoneReceiver extends BroadcastReceiver {
    public static final String INTENT_PHONE_STR = "phone";
    public static final String INTENT_STATE_BOOL = "state";
    //手机号
    private static String phone;
    //是否拨打电话
    private static boolean isDial;

    @Override
    public void onReceive(Context context, Intent intent) {
        // 数据为空处理
        if (intent == null) {
            intent = new Intent();
        }

        if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {// 打出号码
            String curPhone = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            phone = curPhone;
            isDial = true;
            return;
        }

        // 电话监听
        TelephonyManager telMgr = (TelephonyManager) context
                .getSystemService(Service.TELEPHONY_SERVICE);
        switch (telMgr.getCallState()) {
        case Telepho

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值