Skip to content

Commit

Permalink
fix: audio permission issue for Android 14
Browse files Browse the repository at this point in the history
Signed-off-by: qwq233 <qwq233@qwq2333.top>
  • Loading branch information
qwq233 committed Dec 10, 2023
1 parent b111b08 commit 286850c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4229,7 +4229,14 @@ private void showIncomingNotification(String name, TLObject userOrChat, boolean
builder.addAction(R.drawable.ic_call, answerTitle, answerPendingIntent);
incomingNotification = builder.getNotification();
}
startForeground(ID_INCOMING_CALL_NOTIFICATION, incomingNotification);
if (Build.VERSION.SDK_INT >= VERSION_CODES.UPSIDE_DOWN_CAKE) {
if (PermissionUtils.isAudioPermissionGranted()) {
startForeground(ID_INCOMING_CALL_NOTIFICATION, incomingNotification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE | ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK | ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA);
}
} else {
startForeground(ID_INCOMING_CALL_NOTIFICATION, incomingNotification);
}
startRingtoneAndVibration();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ object PermissionUtils {
@JvmStatic
fun isAudioPermissionGranted(): Boolean = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
isPermissionGranted(Manifest.permission.READ_MEDIA_AUDIO) && isPermissionGranted(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)
&& isPermissionGranted(Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
isPermissionGranted(Manifest.permission.READ_MEDIA_AUDIO)
} else {
Expand Down Expand Up @@ -135,6 +136,7 @@ object PermissionUtils {
activity,
BasePermissionsActivity.REQUEST_CODE_EXTERNAL_STORAGE,
Manifest.permission.READ_MEDIA_AUDIO,
Manifest.permission.FOREGROUND_SERVICE_MICROPHONE,
Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED
)
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
Expand Down

0 comments on commit 286850c

Please sign in to comment.