繁体   English   中英

android 11 (api 30): 后台服务录音不工作

[英]android 11 (api 30): recording voice in background service no working

为了在 API 29 及更低版本的后台录制通话和语音,我没有任何问题(我同时使用接收器和后台服务)但是当我使用 API 30 及更高版本时,我的应用程序崩溃permission denied

在我的研究中,我必须使用accessibility service ,但我不知道如何!

<service
     android:name=".recordService"
     android:process=":remote"
     android:foregroundServiceType="microphone"
     android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
     android:exported="true">
     <intent-filter>
          <action android:name="android.accessibilityservice.AccessibilityService" />
     </intent-filter>
     <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibilityservice" />
</service>

<receiver
    android:name="ReceiverSMS"
    android:process=":remote"
    android:enabled="true"
    android:permission="android.permission.BROADCAST_SMS"
    android:exported="true">
    <intent-filter>
       <!-- BROADCAST_SMS -->
       <action android:name="android.provider.Telephony.SMS_DELIVER" />
       <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
       <!-- CALL -->
       <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
       <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(__FILE__);

要允许在服务中录音,您可以使用ref

<manifest>
    ...
    <service ...
        android:foregroundServiceType="microphone" />
</manifest>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM