Android录音文件

本文探讨了在Android平台上实现自动拨打电话、挂断电话、获取录音文件、监听电话状态以及应对后台驻留挑战的方法。通过动态申请权限、使用aidl、PhoneStateListener和广播接收器等技术,实现了电话功能的自动化和录音文件的获取。同时,文章提到了Android后台运行的限制和解决策略,包括权限设置、系统定制及心跳机制的应用。
摘要由CSDN通过智能技术生成

Android电话录音文件


本人最近开发电话软件,大概是通过pc分发指令,实现电话拨打,挂机,录音文件上传功能,说起来是和简单,实际还是遇到很多问题,现在贴出来,与猿友一起共勉。

问题一:实现自动拨打电话,有人认为只能最多实现跳转到拨号界面,这是不可能的,现在跳转到拨号界面,并自动拨号的方式,前提要动态申请权限哦

    /**
     * 拨打电话(直接拨打电话
     *
     * @param context
     * @param phoneNum 电话号码
     */
    public void callPhone(Context context, String phoneNum) {
   
        Intent intent = new Intent(Intent.ACTION_CALL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        context.startActivity(intent);
    }

问题二:自动挂断电话,这个东西由于Android系统设有安全权限,只能通过aidl拿到权限,新建aidl文件,此时要注意路径,在这里插入图片描述

package com.android.internal.telephony;
 /**
 * Interface used to interact with the phone. Mostly this is used by the
 * TelephonyManager class. A few places are still using this directly.
 * Please clean them up if possible and use TelephonyManager instead.
 * {@hide}
 */

interface ITelephony {
   
 /**
 * End call or go to the Home screen
 * @return whether it hung up
 */
 boolean endCall();
 
 }
    public void endCallnew() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, RemoteException {
   
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        Class clazz = Class.forName(telephonyManager.getClass().getName());
        Method method = clazz.getDeclaredMethod("getITelephony");
        method.setAccessible(true);
        ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);
        telephonyService.endCall();
    }

如果你这样写可能就是没有办法适配9.0,这个9.0适配也是找了很久,有个哥们说看到谷歌说是这样解决的。完整的解决方案应该是这样的

 @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值