![](/img/trans.png)
[英]requestLegacyExternalStorage is not working in 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.