android – 更新通知振动铃声

android – 更新通知振动铃声,第1张

概述我正在使用NotificationManager构建器在我的应用程序中显示警报.我知道notify方法的第一个参数是id,如果通知已经可见,框架将更新通知,但是如果我将警报设置为播放铃声振动,如果警报是警报,则铃声/振动也会触发更新? NotificationCompat.Builder nb = new NotificationCompat.Builder(this); nb.setC 我正在使用notificationmanager构建器在我的应用程序中显示警报.我知道notify方法的第一个参数是ID,如果通知已经可见,框架将更新通知,但是如果我将警报设置为播放铃声或振动,如果警报是警报,则铃声/振动也会触发更新?
NotificationCompat.Builder nb = new NotificationCompat.Builder(this);    nb.setContentTitle("Title");    nb.setContentText("message");    nb.setSmallicon(getResources().getIDentifIEr("drawable/alert",null,packagename));    nb.setWhen(System.currentTimeMillis());    nb.setautoCancel(true);    nb.setTicker("message");    final Uri ringtone = Uri.parse(PreferenceManager.getDefaultSharedPreferences(this).getString("ringtone",getString(R.string.settings_default_ringtone)));    nb.setDefaults(Notification.DEFAulT_VIBRATE);    nb.setSound(ringtone);          nb.setDefaults(Notification.DEFAulT_liGHTS);    notificationmanager nm = (notificationmanager)getSystemService(Context.NOTIFICATION_SERVICE);    final Intent notificationIntent = new Intent(this,Main.class);    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_top | Intent.FLAG_ACTIVITY_NEW_TASK);    final PendingIntent contentIntent = PendingIntent.getActivity(this,notificationIntent,0);    nb.setContentIntent(contentIntent);    Notification notification = nb.getNotification();    nm.notify(0,notification);
解决方法 我自己测试了一下,振动/铃声即使在更新时也会启动.

更新:只是更新,如果您使用NotificationCompat.Builder或Notification.Builder,您可以将setonlyAlertOnce设置为仅响铃铃声/振动一次.

总结

以上是内存溢出为你收集整理的android – 更新通知振动/铃声全部内容,希望文章能够帮你解决android – 更新通知振动/铃声所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1135118.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存