安卓检查通话自动录音功能是否开启,并跳转到开启页面

这篇具有很好参考价值的文章主要介绍了安卓检查通话自动录音功能是否开启,并跳转到开启页面。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

介绍

本文章主要介绍安卓检查通话自动录音功能是否开启,并跳转到相应的开启页面,主要介绍小米,华为、vivo和oppo手机,其他手机暂不做介绍

检查手机自动录音

小米

/**
     * 检查小米手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkXiaomiRecord() throws Settings.SettingNotFoundException {
        int key = Settings.System.getInt(mContext.getContentResolver(), "button_auto_record_call");
//            XLog.d(TAG, "Xiaomi key:" + key);
        //0是未开启,1是开启
        return key != 0;
    }

OPPO

/**
     * 检查OPPO手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkOppoRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Global.getInt(mContext.getContentResolver(), "oplus_customize_all_call_audio_record");
//        int key = Settings.Global.getInt(mContext.getContentResolver(), "oppo_all_call_audio_record");
//            XLog.d(TAG, "Oppo key:" + key);
        //0代表OPPO自动录音未开启,1代表OPPO自动录音已开启
        return key != 0;
    }

VIVO

/**
     * 检查VIVO自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkVivoRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Global.getInt(mContext.getContentResolver(), "call_record_state_global");
//            XLog.d(TAG, "Vivo key:" + key);
        //0代表VIVO自动录音未开启,1代表VIVO所有通话自动录音已开启,2代表指定号码自动录音
        return key == 1;
    }

华为

/**
     * 检查华为手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkHuaweiRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Secure.getInt(mContext.getContentResolver(), "enable_record_auto_key");
//            XLog.d(TAG, "Huawei key:" + key);
        //0代表华为自动录音未开启,1代表华为自动录音已开启
        return key != 0;
    }

跳转页面

小米

/**
     * 跳转到小米开启通话自动录音功能页面
     */
    private void startXiaomiRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.settings.CallRecordSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

oppo

/**
     * 跳转到OPPO开启通话自动录音功能页面
     */
    private void startOppoRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.OplusCallFeaturesSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

vivo

/**
     * 跳转到VIVO开启通话自动录音功能页面
     */
    private void startVivoRecord() {
        ComponentName componentName = new ComponentName("com.android.incallui", "com.android.incallui.record.CallRecordSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

华为

/**
     * 跳转到华为开启通话自动录音功能页面
     */
    private void startHuaweiRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.MSimCallFeaturesSetting");
//        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.recorder");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

工具包

作者通过上面的例子做了一个开箱即用的工具包,代码复制过去直接使用即可,代码如下:文章来源地址https://www.toymoban.com/news/detail-780517.html

PhoneUtils

package com.outsource.uni.phone.service;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.Settings;

import com.alibaba.fastjson.JSONObject;
import com.outsource.uni.phone.utils.FileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class PhoneUtils {
    private static PhoneUtils instance;
    private static Context mContext;

    public PhoneUtils(Context context) {
        mContext = context;
    }

    public static synchronized PhoneUtils getInstance(Context context) {
        mContext = context;
        if (instance == null) {
            instance = new PhoneUtils(context);
        }

        return instance;
    }

    /**
     * 判断是否开启通话自动录音功能
     */
    public boolean checkIsAutoRecord() throws Settings.SettingNotFoundException {
        boolean isOpen = false;
        String manufacturer = Build.MANUFACTURER.toLowerCase();
        if (manufacturer.contains("huawei")) {
            isOpen = checkHuaweiRecord();
        } else if (manufacturer.contains("xiaomi")) {
            isOpen = checkXiaomiRecord();
        } else if (manufacturer.contains("oppo")) {
            isOpen = checkOppoRecord();
        } else if (manufacturer.contains("vivo")) {
            isOpen = checkVivoRecord();
        }
        return isOpen;
    }

    /**
     * 跳转到通话自动录音页面
     */
    public void toCallAutoRecorderPage() {
        String manufacturer = Build.MANUFACTURER.toLowerCase();
        if (manufacturer.contains("huawei")) {
            startHuaweiRecord();
        } else if (manufacturer.contains("xiaomi")) {
            startXiaomiRecord();
        } else if (manufacturer.contains("oppo")) {
            startOppoRecord();
        } else if (manufacturer.contains("vivo")) {
            startVivoRecord();
        }
    }

    /**
     * 获取所有录音文件
     */
    public List<String> getAllRecorderFiles() {
        //获取录音文件夹
        File recorderDirFile = getRecorderDirFile();
        return FileUtil.getAllFiles(recorderDirFile, false);
    }

    /**
     * 获取设置的key和value
     */
    public JSONObject getSettingsKeyValue() {
        JSONObject object = new JSONObject();
        List<String> systemKeyValue = getSettingsKeyValue(Settings.System.CONTENT_URI);
        List<String> secureKeyValue = getSettingsKeyValue(Settings.Secure.CONTENT_URI);
        List<String> globalKeyValue = getSettingsKeyValue(Settings.Global.CONTENT_URI);
        object.put("system", systemKeyValue);
        object.put("secure", secureKeyValue);
        object.put("global", globalKeyValue);
        return object;
    }


    /**
     * 搜索录音文件
     */
    public File searchRecorderFile(String number) {
        File audioFile = null;
        //获取录音文件夹
        File recorderDirFile = getRecorderDirFile();
        List<String> list = FileUtil.getAllFiles(recorderDirFile, false);
        long thisTime = System.currentTimeMillis();
        if (list.size() > 0) {
            for (String path : list) {
                System.out.println("文件路径:" + path);
                File file = new File(path);
                long lastModified = file.lastModified();
                if (thisTime - lastModified <= 10000) {
                    audioFile = file;
                    System.out.println("退出循环");
                    break;
                }
            }
        }
        return audioFile;
    }

    /**
     * 检查小米手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkXiaomiRecord() throws Settings.SettingNotFoundException {
        int key = Settings.System.getInt(mContext.getContentResolver(), "button_auto_record_call");
//            XLog.d(TAG, "Xiaomi key:" + key);
        //0是未开启,1是开启
        return key != 0;
    }

    /**
     * 检查OPPO手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkOppoRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Global.getInt(mContext.getContentResolver(), "oplus_customize_all_call_audio_record");
//        int key = Settings.Global.getInt(mContext.getContentResolver(), "oppo_all_call_audio_record");
//            XLog.d(TAG, "Oppo key:" + key);
        //0代表OPPO自动录音未开启,1代表OPPO自动录音已开启
        return key != 0;
    }

    /**
     * 检查VIVO自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkVivoRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Global.getInt(mContext.getContentResolver(), "call_record_state_global");
//            XLog.d(TAG, "Vivo key:" + key);
        //0代表VIVO自动录音未开启,1代表VIVO所有通话自动录音已开启,2代表指定号码自动录音
        return key == 1;
    }

    /**
     * 检查华为手机自动录音功能是否开启,true已开启  false未开启
     *
     * @return
     */
    private boolean checkHuaweiRecord() throws Settings.SettingNotFoundException {
        int key = Settings.Secure.getInt(mContext.getContentResolver(), "enable_record_auto_key");
//            XLog.d(TAG, "Huawei key:" + key);
        //0代表华为自动录音未开启,1代表华为自动录音已开启
        return key != 0;
    }

    /**
     * 跳转到VIVO开启通话自动录音功能页面
     */
    private void startVivoRecord() {
        ComponentName componentName = new ComponentName("com.android.incallui", "com.android.incallui.record.CallRecordSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    /**
     * 跳转到小米开启通话自动录音功能页面
     */
    private void startXiaomiRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.settings.CallRecordSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    /**
     * 跳转到华为开启通话自动录音功能页面
     */
    private void startHuaweiRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.MSimCallFeaturesSetting");
//        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.recorder");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    /**
     * 跳转到OPPO开启通话自动录音功能页面
     */
    private void startOppoRecord() {
        ComponentName componentName = new ComponentName("com.android.phone", "com.android.phone.OplusCallFeaturesSetting");
        Intent intent = new Intent();
        intent.setComponent(componentName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);
    }

    /**
     * 获取录音文件夹
     *
     * @return
     */
    private File getRecorderDirFile() {
        String manufacturer = Build.MANUFACTURER.toLowerCase();
        String parentPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        File childFile = null;
        if (manufacturer.contains("huawei")) {
            if (FileUtil.isFileExist(parentPath + "/Sounds/CallRecord")) {
                childFile = new File(parentPath + "/Sounds/CallRecord");
            } else if (FileUtil.isFileExist(parentPath + "/record")) {
                childFile = new File(parentPath + "record");
            } else if (FileUtil.isFileExist(parentPath + "/Record")) {
                childFile = new File(parentPath + "/Record");
            } else {
                childFile = new File("");
            }
        } else if (manufacturer.contains("xiaomi")) {
            childFile = new File(parentPath + "/MIUI/sound_recorder/call_rec/");
        } else if (manufacturer.contains("meizu")) {
            childFile = new File(parentPath + "/Recorder");
        } else if (manufacturer.contains("oppo")) {
            childFile = new File(parentPath + "/Recordings");
        } else if (manufacturer.contains("vivo")) {
            if (FileUtil.isFileExist(parentPath + "/Recordings/Record/Call")) {
                childFile = new File(parentPath + "/Recordings/Record/Call");
            } else {
                childFile = new File(parentPath + "/Record/Call");
            }
        } else {
            childFile = new File("");
        }
        return childFile;
    }

    /**
     * 获取key和value
     */
    private List<String> getSettingsKeyValue(Uri uri){
        List<String> list = new ArrayList<>();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            @SuppressLint("Recycle") Cursor cursor = mContext.getContentResolver().query(uri, null, null, null);
            String[] columnNames = cursor.getColumnNames();
            StringBuilder builder = new StringBuilder();
            while (cursor.moveToNext()) {
                for (String columnName : columnNames) {
                    @SuppressLint("Range") String string = cursor.getString(cursor.getColumnIndex(columnName));
                    try {
                        if(string.toLowerCase().contains("record") || string.toLowerCase().contains("call")){
                            builder.append(columnName).append(":").append(string).append("\n");
                            list.add(columnName + ":" + string);
                        }
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        }
        return list;
    }
}

 FileUtil

package com.outsource.uni.phone.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.Reader;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class FileUtil {
    private static final String TAG = "FileUtil";
    /**
     * 判断SD卡上的文件是否存在
     */
    public static boolean isFileExist(String fileName) {
        File file = new File(fileName);
        return file.exists();
    }

    /**
     * searchFile 查找文件并加入到ArrayList 当中去
     *
     * @param context
     * @param keyword
     * @param filepath
     * @return
     */
    public static List<JSONObject> searchFile(Context context, String keyword, File filepath) {
        List<JSONObject> list = new ArrayList<>();
        JSONObject rowItem = null;
        int index = 0;
        // 判断SD卡是否存在
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            File[] files = filepath.listFiles();
            if (files != null && files.length > 0) {
                for (File file : files) {
                    if (file.isDirectory()) {
                        if (file.getName().replace(" ", "").toLowerCase().contains(keyword)) {
                            rowItem = new JSONObject();
                            rowItem.put("number", index); // 加入序列号
                            rowItem.put("fileName", file.getName());// 加入名称
                            rowItem.put("path", file.getPath()); // 加入路径
                            rowItem.put("size", file.length() + ""); // 加入文件大小
                            list.add(rowItem);
                        }
                        // 如果目录可读就执行(一定要加,不然会挂掉)
                        if (file.canRead()) {
                            list.addAll(searchFile(context, keyword, file)); // 如果是目录,递归查找
                        }
                    } else {
                        // 判断是文件,则进行文件名判断
                        try {
                            if (file.getName().replace(" ", "").contains(keyword) || file.getName().replace(" ", "").contains(keyword.toUpperCase())) {
                                rowItem = new JSONObject();
                                rowItem.put("number", index); // 加入序列号
                                rowItem.put("fileName", file.getName());// 加入名称
                                rowItem.put("path", file.getPath()); // 加入路径
                                rowItem.put("size", file.length() + ""); // 加入文件大小
                                list.add(rowItem);
                                index++;
                            }
                        } catch (Exception e) {
//                            Toast.makeText(context, "查找发生错误!", Toast.LENGTH_SHORT).show();
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        return list;
    }

    /**
     * 得到所有文件
     *
     * @param dir
     * @return
     */
    public static ArrayList<String> getAllFiles(File dir, boolean child) {
        ArrayList<String> allFiles = new ArrayList<String>();
        // 递归取得目录下的所有文件及文件夹
        File[] files = dir.listFiles();
        if (files == null) {
            return allFiles;
        }
        for (int i = 0; i < Objects.requireNonNull(files).length; i++) {
            File file = files[i];
//            allFiles.add(file.getPath());
            if (file.isDirectory() && child) {
                if (file.canRead()) {
                    allFiles.addAll(getAllFiles(file, child));
                }
            } else {
                allFiles.add(file.getPath());
            }
        }
        return allFiles;
    }
}

到了这里,关于安卓检查通话自动录音功能是否开启,并跳转到开启页面的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 基于SpringBoot自定义控制是否需要开启定时功能

    在基于SpringBoot的开发过程中,有时候会在应用中使用定时任务,然后服务器上启动定时任务,本地就不需要开启定时任务,使用一个参数进行控制,通过查资料得知非常简单。 在 application-dev.yml 中加入如下配置 或者其实也不需要 SchedulerCondition ,直接写也可以的 以上即可解

    2024年01月15日
    浏览(73)
  • [AudioRecorder]iPhone苹果通话录音汉化破解版-使用巨魔安装-ios17绕道目前还不支持

    首先你必须有 巨魔 才能使用!! 不会安装的,还没安装的 移步这里 ,ios17 以上目前装不了,别看了:永久签名 | 网址分类目录 | 路灯iOS导航-苹果签名实用知识网址导航-各种iOS技巧-后厂村路灯  视频教程 【AudioRecorder】iPhone通话录音汉化破解版-使用巨魔安装-ios17绕道目前

    2024年02月20日
    浏览(155)
  • 解决苹果Safari 浏览器下html不能自动播放声音和视频的问题-实时语音通话功能【唯一客服】...

    在实现我的客服系统中,实时语音通话功能的时候,如果想自动播放音视频流,在苹果设备上遇到了问题。 苹果浏览器(Safari)在默认情况下不允许声音在背景里自动播放。这是出于用户体验和隐私方面的考虑,避免在用户没有意识到的情况下自动播放声音。 解决办法是 iOS

    2024年02月12日
    浏览(89)
  • 微信小程序检查录音权限并引导用户进入设置页面

    wx.startRecord(Object object) :开始录音接口,调用该接口后,小程序将会录制音频,最长可以录制60秒。 wx.stopRecord() :停止录音接口,调用该接口后,录音将停止并生成音频文件。 wx.pauseVoice() :暂停播放音频接口,调用该接口后,正在播放的音频将会暂停。 wx.resumeVoice() :继续

    2024年02月03日
    浏览(70)
  • uniapp 安卓如何获取通话权限,监听通话情况

    本篇文章还是主要讲解uniapp知识,那么在uniapp中如何去实现监听通话的权限?接下来请看代码 在页面中调用方法 监听通话状态

    2024年02月16日
    浏览(38)
  • 京东自动化功能之商品信息监控是否有库存

    这里有两个参数,分别是area和skuids area是地区编码,我这里统计了全国各个区县的area编码,用户可以根据实际地址进行构造 skuids是商品的信息ID 填写好这两个商品之后,会显示两种状态,判断有货或者无货状态,详情如下图所示 简单编写下python代码,比如我们的地址是北京

    2024年02月17日
    浏览(44)
  • Android 应用自动开启辅助(无障碍)功能并使用辅助(无障碍)功能

    目录 一.背景 二.前提条件 三.将普通应用转换成系统应用 1.在AndroidManifest文件中添加

    2024年02月09日
    浏览(32)
  • 在 Android 上恢复已删除的通话记录 - 安卓手机通话记录恢复技巧

    有时,Android 用户会在内存空间用完时删除他们的通话记录。他们认为那些电话通话记录将不再需要了,但突然出于某些原因他们需要恢复那些已删除的通话记录。 恢复已删除的照片、视频、音乐、短信和通话记录等数据在以前是一件很难的事情。但是现在如果你想恢复一个

    2024年02月08日
    浏览(42)
  • 手机开启这项功能,来电时自动播报对方姓名和号码,便捷实用

    随着智能手机的普及,我们的生活变得越来越便捷。然而,当我们正在忙碌或者手头没有手机时,突然来了一个电话,我们可能会错过重要的电话或者在不方便接听的情况下错失机会。但是,如果你开启了来电语音报号和姓名功能,手机会在来电时自动播报来电者的名字和号

    2024年04月28日
    浏览(101)
  • Appium微信小程序自动化之开启webview调试功能方法封装

    Appium在微信小程序自动化时,需要开启微信的webview调试功能,以方便对webview的元素进行定位。 运行代码之后,可以顺利打开微信,通过向自己发送消息并点击消息,开启webview调试功能: 看到这个页面后,表示启动微信webview调试功能启动生效。 欢迎技术交流:

    2024年04月13日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包