我正在为android api 21-29开发网络广播应用程序,一切都很好,但有一个案例让我感到困惑。在华为荣誉10上,当我的应用程序开始播放并尝试打开蓝牙时,一切都不起作用。设备关闭蓝牙和所有功能。我将此权限添加到我的androidmanifest.xml中
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
如果蓝牙在播放前打开,他会在开始播放后立即关闭。我在app send mediasession.onplay时使用了此方法
@Override
public void onPlay() {
if (!exoPlayer.getPlayWhenReady()) {
startService(new Intent(getApplicationContext(), PlayerService.class));
if (stationsRepository == null)
return;
station = stationsRepository.getCurrent();
bitrate = Connectivity.currentBitrate;
String stream = station.getStreamByBitrate(bitrate);
prepareToPlay(Uri.parse(stream));
mediaSession.setQueueTitle(station.getTitle());
if (!audioFocusRequested) {
audioFocusRequested = true;
int audioFocusResult;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
audioFocusResult = audioManager.requestAudioFocus(audioFocusRequest);
} else {
audioFocusResult = audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}
if (audioFocusResult != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
return;
}
mediaSession.setActive(true);
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
exoPlayer.setPlayWhenReady(true);
}
mediaSession.setPlaybackState(stateBuilder.setState(PlaybackStateCompat.STATE_PLAYING, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1).build());
currentState = PlaybackStateCompat.STATE_PLAYING;
refreshNotificationAndForegroundStatus(currentState);
}
在使用安卓10、安卓8、安卓7的相同设备上,所有工作正常。谁能帮我修一下这个。
p、 对不起我的英语。这是我第一次用这种语言提问。
更新:在华为p30 lite上测试,并捕获此错误。
暂无答案!
目前还没有任何答案,快来回答吧!