要在Android上解决Firefox不显示媒体设备的问题,可以尝试以下解决方案:
private static final int PERMISSION_REQUEST_CODE = 1;
private void requestPermissionsIfNeeded() {
String[] permissions = {Manifest.permission.RECORD_AUDIO, Manifest.permission.MODIFY_AUDIO_SETTINGS};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
for (String permission : permissions) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, permissions, PERMISSION_REQUEST_CODE);
return;
}
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_CODE) {
boolean allPermissionsGranted = true;
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
allPermissionsGranted = false;
break;
}
}
if (allPermissionsGranted) {
// 权限已授予,执行相关操作
} else {
// 权限未授予,显示适当的消息或禁用相关功能
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
这些解决方案应该可以解决Android上Firefox不显示媒体设备的问题。请注意,根据您的具体情况,可能需要调整代码以适应您的应用程序。