[英]Android 7.0 : Custom notification sound not working anymore
因此,我的代码在1个月前运行良好。 但是现在我的自定义声音根本无法播放。
我的设备 :小米Note 4
Android 7.0 版 NRD90M
我整天都在互联网上搜索,但是找不到任何有效的解决方案。 关于我的问题有什么更新吗?
有效载荷
{body={"notification_type":"","booking_id":"","booking_no_text":"","guest_mobile":"","ride_date":"","guest_name":"","pickup_longitude":"","reporting_time":"","fyear":"","pickup_latitude":"","pickup_address":""}, icon=, sound=, title=Booking Notification}
通知生成器
final Intent service = new Intent(this, MessagingService.class);
service.putExtra("msg", "New Trip Request");
startService(service);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(msg_content)
.setAutoCancel(true)
.setSound(sound)
.setVibrate(new long[]{500, 0000, 0000, 500, 000});
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setColor(ContextCompat.getColor(mContext,R.color.colorPrimary));
} else {
mBuilder.setSmallIcon(R.drawable.ic_launcher);
}
NotificationManager mnNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = mContext.getString(R.string.default_notification_channel_id);
NotificationChannel channel = new NotificationChannel(channelId, title, NotificationManager.IMPORTANCE_DEFAULT);
mnNotificationManager.createNotificationChannel(channel);
mBuilder.setChannelId(channelId);
}
mnNotificationManager.notify(0, mBuilder.build());
stopService(service);
之前的声音播放得很完美。 但是突然停止了工作。
经过2天的挫折,我找到了解决方案。 如果您使用的是MI手机,并且最近更新了UI。 然后,您要做的就是在设置中启用应用的声音
转到 :设置>通知和状态栏>应用通知>选择应用并启用声音。
参考链接: https : //www.reddit.com/r/Xiaomi/comments/906p09/notification_sounds_not_working_on_miui_10_8719/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.