Vivo 华为设备 AudioManager做了什么

Android:华为Vivo设备上AudioManager.setStreamMute导致的问题
在Android 7.0及以上版本,华为和Vivo设备使用`AudioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false)`可能导致应用崩溃。为避免此问题,应用需在清单文件中注册`ACCESS_NOTIFICATION_POLICY`权限。本文介绍了AudioManager相关方法,如调整音量、设置麦克风静音和铃声模式,以及遇到的静音模式下的兼容性挑战。" 134593041,7481841,Q*与Q Transformer:深度强化学习在A*搜索与机器人自主学习的新突破,"['人工智能', '深度学习', '机器人技术', '强化学习', '算法优化']

今天收到测试小姐姐这样一个bug反馈,我的拍照闪退了,小哥哥快点帮我看看。

立即bugly看日志看到

java.lang.SecurityException: Not allowed to change Do Not Disturb state
    at android.os.Parcel.readException(Parcel.java:2016)
    at android.os.Parcel.readException(Parcel.java:1962)
    at android.media.IAudioService$Stub$Proxy.adjustStreamVolume(IAudioService.java:925)
    at android.media.AudioManager.adjustStreamVolume(AudioManager.java:808)
    at android.media.AudioManager.setStreamMute(AudioManager.java:1148)
    at com.xxxxxxxx.activity.CustomCameraActivity$3.run(CustomCameraActivity.java:376)
    at android.os.Handler.handleCallback(Handler.java:809)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7383)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
    
package com.example.myapplication; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Build; import android.util.Log; public class ExtendTCPServer { private final Context context; private static final String TAG = "ExtendTCPServer"; // FM相关变量 private AudioManager audioManager; private boolean isFmActive = false; private double currentFrequency = 0.0; public ExtendTCPServer(Context context) { this.context = context; this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); } public String handleExtendedCommand1(String command) { if (command == null) return null; String[] parts = command.split("\\s+"); String cmd = parts[0].toLowerCase().trim(); switch (cmd) { case "fmstart": if (parts.length < 2) { return "FM_ERROR:Missing frequency parameter, format: fmstart frequency"; } return fmStart(parts[1]); case "fmstop": return fmStop(); case "fmstatus": return fmStatus(); case "fmseekup": return fmSeekUp(); case "fmseekdown": return fmSeekDown(); default: return null; } } private String fmStart(String frequencyStr) { try { double frequency = Double.parseDouble(frequencyStr); if (frequency < 87.5 || frequency > 108.0) { return "FM_ERROR:Frequency must be between 87.5 and 108.0 MHz"; } boolean success = startFmRadio(frequency); if (success) { isFmActive = true; currentFrequency = frequency; return String.format("FM_STARTED:%.1fMHz", frequency); } else { return "FM_ERROR:Failed to start FM radio"; } } catch (NumberFormatException e) { return "FM_ERROR:Invalid frequency format, must be a number"; } catch (Exception e) { Log.e(TAG, "FM start error: " + e.getMessage()); return "FM_ERROR:" + e.getMessage(); } } private String fmStop() { if (!isFmActive) { return "FM_ERROR:FM radio is not active"; } boolean success = stopFmRadio(); if (success) { isFmActive = false; resetAudio(); return "FM_STOPPED"; } else { return "FM_ERROR:Failed to stop FM radio"; } } private String fmStatus() { return String.format("FM_STATUS:active=%b,frequency=%.1fMHz", isFmActive, currentFrequency); } private String fmSeekUp() { if (!isFmActive) { return "FM_ERROR:FM radio is not active"; } // 向上搜索下一个可用频道 (增加0.1MHz) double newFrequency = Math.min(108.0, currentFrequency + 0.1); boolean success = startFmRadio(newFrequency); if (success) { currentFrequency = newFrequency; return String.format("FM_SEEK_UP:%.1fMHz", newFrequency); } else { return "FM_ERROR:Seek failed"; } } private String fmSeekDown() { if (!isFmActive) { return "FM_ERROR:FM radio is not active"; } // 向下搜索下一个可用频道 (减少0.1MHz) double newFrequency = Math.max(87.5, currentFrequency - 0.1); boolean success = startFmRadio(newFrequency); if (success) { currentFrequency = newFrequency; return String.format("FM_SEEK_DOWN:%.1fMHz", newFrequency); } else { return "FM_ERROR:Seek failed"; } } //重置音频设置 private void resetAudio() { try { audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setSpeakerphoneOn(false); } catch (Exception e) { Log.e(TAG, "Audio reset error: " + e.getMessage()); } } private boolean startFmRadio(double frequency) { try { //启动FM收音机功能并调频到指定频率的 Intent intent = new Intent(); intent.setAction("com.vivo.fmradio");//三星、小米、华为 intent.putExtra("freq", (float) frequency); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent); return true; } Intent intent2 = new Intent(); intent2.setAction("android.intent.action.MAIN"); intent2.addCategory("android.intent.category.APP_FMRADIO"); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (intent2.resolveActivity(context.getPackageManager()) != null) { context.startActivity(intent2); return true; } Intent broadcastIntent = new Intent("com.android.fmradio.transmitter"); broadcastIntent.putExtra("state", true); broadcastIntent.putExtra("freq", (float) frequency); context.sendBroadcast(broadcastIntent); return true; } catch (Exception e) { Log.e(TAG, "Start FM radio error: " + e.getMessage()); return false; } } private boolean stopFmRadio() { try { // 发送停止广播 Intent broadcastIntent = new Intent("com.android.fmradio.transmitter"); broadcastIntent.putExtra("state", false); //表示要关闭FM收音机 context.sendBroadcast(broadcastIntent); return true; } catch (Exception e) { Log.e(TAG, "Stop FM radio error: " + e.getMessage()); return false; } } //检查设备是否支持FM收音机 public boolean isFmSupported() { try { // 检查是否有FM收音机相关的组件 Intent intent = new Intent(); intent.setAction("com.android.fm.player.FmRadioActivity"); return intent.resolveActivity(context.getPackageManager()) != null; } catch (Exception e) { return false; } } }这个代码基础上改现在根本就收不到,没有播放任何声音
最新发布
11-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值