我只有SDK28模拟器有一个奇怪的问题。在旧版本上一切正常。
借助于前台服务,我正在启动一个通知,该通知应该同时具有声音和振动。我的问题是28SDK仿真器上没有声音,也没有“振动(根据logcat)”
private void setNotification(final Context context, long ID){
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
PendingIntent tmp = PendingIntent.getActivity(context, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setFullScreenIntent(tmp, true);
final NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
if(manager != null) {
String channelName = "ChannelName";
mChannel = new NotificationChannel(channelName, channelName, NotificationManager.IMPORTANCE_HIGH) Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), notification);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setFlags(AudioAttributes.USAGE_ALARM)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
mChannel.setSound(notification, audioAttributes);
long[] vibrationPattern = new long[]{0, 300, 700, 300, 700};
mChannel.enableVibration(true);
mChannel.setVibrationPattern(vibrationPattern);
builder.setChannelId(channelName);
Notification notification = builder.build();
startForeground((int) ID, notification);
}
}
我不能简单地从28SDK仿真器上的扬声器听到声音。另一方面,该振动作为错误记录在logcat上:
1919-11280 / system_process E / VibratorService:vibratorOn命令失败(1)。
在其他模拟器上,振动记录为成功,但显然未在模拟器上显示。
谢谢!